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

Replace DefaultServerCapabilities with NewDefaultServerCapabilities()… #360

Merged
merged 2 commits into from
Feb 4, 2024

Conversation

thedevop
Copy link
Collaborator

@thedevop thedevop commented Jan 14, 2024

… to avoid data race

In tests, Capabilities maybe altered. However, DefaultServerCapabilities is a single global instance, where it maybe embedded in running server instances. So when value is altered, tests may fail with data race issue.

Here is an example:
In TestServerProcessSubscribeACLCheckDenyObscure:

server/server_test.go

Lines 2790 to 2794 in 65c7853

func TestServerProcessSubscribeACLCheckDenyObscure(t *testing.T) {
s := New(&Options{
Logger: logger,
})
_ = s.Serve()

and TestServerClearExpiredRetained
s.Options.Capabilities.MaximumMessageExpiryInterval = 0

are seemingly different tests, but they cause interferences and resulted in data race issue.

This surfaced in the failed test for PR #359.

Note, this is mostly a test issue, as normally one would (should) not alter server capabilities once server started serving.

This may also be the cause for data race issue seen in #200.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 7773058128

  • 0 of 18 (100.0%) changed or added relevant lines in 1 file are covered.
  • 6 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.1%) to 98.648%

Files with Coverage Reduction New Missed Lines %
server.go 6 99.14%
Totals Coverage Status
Change from base Build 7495506564: -0.1%
Covered Lines: 5545
Relevant Lines: 5621

💛 - Coveralls

@mochi-co
Copy link
Collaborator

mochi-co commented Feb 4, 2024

This is a very nice fix, thank you @thedevop. I really like what you've done here.

@mochi-co mochi-co merged commit 686c35a into mochi-mqtt:main Feb 4, 2024
2 of 3 checks passed
@thedevop thedevop deleted the data_race branch February 4, 2024 21:11
@thedevop thedevop restored the data_race branch February 4, 2024 21:11
@thedevop thedevop deleted the data_race branch February 4, 2024 21:13
mochi-co added a commit that referenced this pull request Mar 18, 2024
… to avoid data race (#360)

Co-authored-by: JB <28275108+mochi-co@users.noreply.github.com>
mochi-co added a commit that referenced this pull request Mar 18, 2024
* Implement file-based configuration

* Implement file-based configuration

* Replace DefaultServerCapabilities with NewDefaultServerCapabilities() to avoid data race (#360)

Co-authored-by: JB <28275108+mochi-co@users.noreply.github.com>

* Only pass a copy of system.Info to hooks (#365)

* Only pass a copy of system.Info to hooks

* Rename Itoa to Int64toa

---------

Co-authored-by: JB <28275108+mochi-co@users.noreply.github.com>

* Allow configurable max stored qos > 0 messages (#359)

* Allow configurable max stored qos > 0 messages

* Only rollback Inflight if QoS > 0

* Only rollback Inflight if QoS > 0

* Minor refactor

* Update server version

* Implement file-based configuration

* Implement file-based configuration

* update configs with maximum_inflight value

* update docker configuration

* fix tests

---------

Co-authored-by: mochi-co <moumochi@icloud.com>
Co-authored-by: thedevop <60499013+thedevop@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

None yet

3 participants