- This topic has 3 replies, 2 voices, and was last updated 3 years, 9 months ago by .
Viewing 3 reply threads
Viewing 3 reply threads
- You must be logged in to reply to this topic.
Dear Kim
kbmMW 5.15.10
I created a version control system based on TkbmMWFileService. I run the test for simultaneously working for kbmMWFileService and I have a few problems
The First
AV in function TkbmMWFileReferences.FindReference(const AID:cardinal; const APath:string):TkbmMWFileReference. I thing items are deleted while this cycle works. May be the GarbageCollector deletes them
for i:=Count-1 downto 0 do
begin
ref:=Items[i];
if (ref.FID=AID) and (ref.FPath=APath) then
begin
Result:=ref;
exit;
end;
end;
Result:=nil;
The Second
I started 400 simultaneously connection, but many from them get socket error 10053 and don’t connect
The Third
The 233 connections were established but only 13 get files from the server and the other 220 connections wait
Thanks
Vadim Mescheryakov
The problem seems in function TkbmMWFilePool.Access(AFilePath:string; const AMode:TkbmMWFileAccessMode; var AToken:integer; var AHandle:THandle; const ADenyWrite:boolean = true):TkbmMWFileReference;
the second call CreateNewFileHandle doesn’t contain ” lst:=FFileReferences.BeginWrite + FFileReferences.EndWrite”
// No token provided, add access and return new token.
AHandle:=CreateNewFileHandle(lst,Result,AFilePath,AMode,AToken);
Are I right?
No, I am not right.
If I add this block the service freezes during sending files
The problem hides in another place. I can see the same error inside the function CreateNewFileHandle. AReferences.Items deleted in some parallel thread and this code show error
if AToken<0 then
begin
// Generate unique random token number.
// Its randomized to minimize the ability to guess a token my
// malicious clients.
repeat
j:=trunc(Random*$0FFFFFFE)+1;
b:=true;
for i:=0 to AReferences.Count-1 do
if AReferences.Items[i].FToken=j then
begin
b:=false;
break;
end;
until b;
AToken:=j;
end;
How can I fix it?
The TkbmMWFilePool should in itself be threadsafe, as long as you are using the Access and ReleaseAccess methods and never manually trying to free any TkbmMWFileReference instance returned by Access.
/Kim