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

Should this library still use x/sync/semaphore? #696

Open
rittneje opened this issue Nov 19, 2024 · 1 comment
Open

Should this library still use x/sync/semaphore? #696

rittneje opened this issue Nov 19, 2024 · 1 comment

Comments

@rittneje
Copy link
Contributor

The v5 library has a comment explaining why it no longer uses x/sync/semaphore.

// This function was previously performed by `golang.org/x/sync/semaphore` but, as per the MQTT spec:
//
// > The send quota is not incremented if it is already equal to the initial send quota. The attempt to increment above
// > the initial send quota might be caused by the re-transmission of a PUBREL packet after a new Network Connection is
// > established.
//
// The result of this happening with `semaphore` is a `panic` which is not ideal.
// It is also possible (as per issue #179) that bugs, or unexpected circumstances, may result in the same situation. For
// example: if the local session state is lost but there is a session state on the server (meaning it sends an unexpected
// PUBACK).

Does this problem also apply to this library? Should it not be using x/sync/semaphore?

@MattBrittan
Copy link
Contributor

The V5 spec mandates how quotas work meaning that the client needs to follow these rules. The V3 spec dows not define this so the implementation here is totally within our control (and much more limited than in the V5 client).

I don't believe there is an issue in this client because it only uses a semaphore to limit the number of messages in flight when sending messages in the store following reconnection (MaxResumePubInFlight). It does not provide the option to limit messages in flight in general. MaxResumePubInFlight was added because it's possible for a lot of messages to be added to the session state while the client is disconnected, and attempting to send them all quickly following reconnection can cause issues (particularly over mobile connections).

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

2 participants