Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ever increasing credits #223

Open
ZfHxFr opened this issue Apr 7, 2022 · 5 comments
Open

Ever increasing credits #223

ZfHxFr opened this issue Apr 7, 2022 · 5 comments

Comments

@ZfHxFr
Copy link

ZfHxFr commented Apr 7, 2022

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
Copy link
Owner

sahlberg commented Apr 7, 2022

maybe a bug in macos ?

@sahlberg
Copy link
Owner

sahlberg commented Apr 7, 2022

Credits are used for flow control between client and server.

@ZfHxFr
Copy link
Author

ZfHxFr commented Apr 9, 2022

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
Copy link

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

@ZfHxFr
Copy link
Author

ZfHxFr commented Nov 25, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants