libsmb2 icon indicating copy to clipboard operation
libsmb2 copied to clipboard

Ever increasing credits

Open ZfHxFr opened this issue 3 years ago • 5 comments

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.

ZfHxFr avatar Apr 07 '22 11:04 ZfHxFr

maybe a bug in macos ?

sahlberg avatar Apr 07 '22 11:04 sahlberg

Credits are used for flow control between client and server.

sahlberg avatar Apr 07 '22 11:04 sahlberg

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.

ZfHxFr avatar Apr 09 '22 12:04 ZfHxFr

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

amandeepgautam avatar Apr 14 '22 00:04 amandeepgautam

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);

ZfHxFr avatar Nov 25 '22 19:11 ZfHxFr