sahlberg / libsmb2

SMB2/3 userspace client
Other
329 stars 139 forks source link

Ever increasing credits #223

Open ZfHxFr opened 2 years ago

ZfHxFr commented 2 years ago

I tried to traverse a share by smb2_opendir_async, concurrently. I use libsmb2 on a mobile project. When traversing a shared folder from Windows, it works well. When traversing a shared folder from MacOS, some of the requests will not reply. The only obvious difference I can find is that, for Window, the smb->credits is relatively stable, between 1900 and 2100. for MacOS, this value increases endlessly, from 1024 all the way to billions. For those without reply, this value is negative.

I don't understand what credits is for.

sahlberg commented 2 years ago

maybe a bug in macos ?

sahlberg commented 2 years ago

Credits are used for flow control between client and server.

ZfHxFr commented 2 years ago

maybe a bug in macos ?

Yes, it's very likely. The workaround I use is to detect negative credits and create a new context, then retry and continue on the new context.

amandeepgautam commented 2 years ago

One alternative is to keep resetting them to MAX_CREDITS again if they overflow (which is very easy to detect).

ZfHxFr commented 2 years ago

maybe a bug in macos ?

@sahlberg

Do you think it is appropriate to avoid this problem directly in the source code by replacing

smb2->credits += smb2->hdr.credit_request_response;

with

if (smb2->credits + smb2->hdr.credit_request_response < 0) {
    smb2->credits = 0x7FFFFFFF;
}  else  {
    smb2->credits += smb2->hdr.credit_request_response;
}

or with

smb2->credits = MIN(smb2->credits + smb2->hdr.credit_request_response, MAX_CREDITS);