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

[fix] Fix data race in checkAndCleanIdleConnections #981

Merged
merged 1 commit into from
Mar 7, 2023

Conversation

RobertIndie
Copy link
Member

Fixes #978

Motivation

From the data race log of the issue:

2023-03-07T02:05:50.0096902Z WARNING: DATA RACE
2023-03-07T02:05:50.0097176Z Read at 0x00c0003bb298 by goroutine 111:
2023-03-07T02:05:50.0097767Z   github.com/apache/pulsar-client-go/pulsar/internal.(*connectionPool).checkAndCleanIdleConnections()
2023-03-07T02:05:50.0098468Z       /pulsar/pulsar-client-go/pulsar/internal/connection_pool.go:157 +0x24d
2023-03-07T02:05:50.0099058Z   github.com/apache/pulsar-client-go/pulsar/internal.StartCleanConnectionsTask.func1()
2023-03-07T02:05:50.0099727Z       /pulsar/pulsar-client-go/pulsar/internal/helper.go:25 +0x47
2023-03-07T02:05:50.0099934Z 
2023-03-07T02:05:50.0100066Z Previous write at 0x00c0003bb298 by goroutine 69:
2023-03-07T02:05:50.0100537Z   github.com/apache/pulsar-client-go/pulsar/internal.(*connection).connect()
2023-03-07T02:05:50.0101126Z       /pulsar/pulsar-client-go/pulsar/internal/connection.go:277 +0x5d2
2023-03-07T02:05:50.0101649Z   github.com/apache/pulsar-client-go/pulsar/internal.(*connection).start.func1()
2023-03-07T02:05:50.0102222Z       /pulsar/pulsar-client-go/pulsar/internal/connection.go:230 +0x34

We can see that the read access of c.log here:

c.log.Debugf("Closed connection due to inactivity.")

is conflict with the write access of c.log here:

c.log = c.log.SubLogger(log.Fields{"local_addr": c.cnx.LocalAddr()})

This caused the data race.

Modifications

  • Using p.log to avoid accessing the c.log

Verifying this change

This change is already covered by existing tests

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): (yes / no)
  • The public API: (yes / no)
  • The schema: (yes / no / don't know)
  • The default values of configurations: (yes / no)
  • The wire protocol: (yes / no)

Documentation

  • Does this pull request introduce a new feature? (yes / no)
  • If yes, how is the feature documented? (not applicable / docs / GoDocs / not documented)
  • If a feature is not applicable for documentation, explain why?
  • If a feature is not documented yet in this PR, please create a followup issue for adding the documentation

@RobertIndie RobertIndie self-assigned this Mar 7, 2023
@RobertIndie RobertIndie merged commit 96bc58f into apache:master Mar 7, 2023
@RobertIndie RobertIndie added this to the v0.10.0 milestone Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flaky test: TestAutoCloseIdleConnection
2 participants