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

Concurrent map access for clients and inflights causes data race #98

Closed
mochi-co opened this issue Sep 2, 2022 · 1 comment
Closed
Assignees
Labels
bug Something isn't working

Comments

@mochi-co
Copy link
Collaborator

mochi-co commented Sep 2, 2022

Earlier today, @muXxer identified an issue in which the broker would crash with fatal errors, caused when the primary server routine and clients attempted to read and write from the inflight messages map simultaneously.

This is a new issue as of 1.3.0, and resulted from the changes made to inflight handling - specifically, allowing the server event loop to scan and resend inflights (where previously, inflights would only be engaged during connection establishment or within the client itself).

The collision occurred between three locations:

  1. Map reads at github.com/mochi-co/mqtt/server.(*Server).ResendClientInflight() (mqtt/server/server.go:912)
  2. Map writes at github.com/mochi-co/mqtt/server/internal/clients.(*Inflight).Delete() (server/internal/clients/clients.go:570)
  3. Map writes at github.com/mochi-co/mqtt/server/internal/clients.(*Clients).Add() (server/internal/clients/clients.go:48)

The problem was reproducible by placing the server under heavy load with inovex/mqtt-stresser, using qos=2 for both the publisher and subscriber: mqtt-stresser -broker tcp://localhost:1883 -num-clients=200 -num-messages=100 -subscriber-qos=2 -publisher-qos=2

A patch is immediately forthcoming and will be released as v1.3.2

@mochi-co
Copy link
Collaborator Author

mochi-co commented Sep 2, 2022

Resolved in v1.3.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant