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

Cleanup some code #296

Merged
merged 1 commit into from Dec 18, 2019
Merged

Cleanup some code #296

merged 1 commit into from Dec 18, 2019

Conversation

kozlovic
Copy link
Member

  • Move all ping related fields into own pingInfo struct.
  • Use connection closed boolean to check/set closed state instead
    of setting nc to nil. That makes sc.nc immutable and not nil
    and so code using that doesn't have to capture/check.
  • Add a pubAckCloseChan that is closed during connection close
    to prevent publish call from being possibly blocked.

Regarding last point, we have tests and I tried to add a new one
but it would not catch the issue unless I would add a sleep in
publishAsync() after check of connection close and before sending
to pubAckChan.
The race is that if the connection is fully closed between these
two lines then if there are enough go routines trying to send to
the pubAckChan or MaxPubAcksInflight is low, the channel could be
full which would block the publishAsync() call.

Signed-off-by: Ivan Kozlovic ivan@synadia.com

- Move all ping related fields into own pingInfo struct.
- Use connection closed boolean to check/set closed state instead
  of setting nc to nil. That makes sc.nc immutable and not nil
  and so code using that doesn't have to capture/check.
- Add a pubAckCloseChan that is closed during connection close
  to prevent publish call from being possibly blocked.

Regarding last point, we have tests and I tried to add a new one
but it would not catch the issue unless I would add a sleep in
publishAsync() after check of connection close and before sending
to pubAckChan.
The race is that if the connection is fully closed between these
two lines then if there are enough go routines trying to send to
the pubAckChan or MaxPubAcksInflight is low, the channel could be
full which would block the publishAsync() call.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
@nats-io nats-io deleted a comment from coveralls Dec 18, 2019
Copy link
Member

@derekcollison derekcollison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kozlovic kozlovic merged commit 3b79c52 into master Dec 18, 2019
@kozlovic kozlovic deleted the ping_and_conn_close_cleanup branch December 18, 2019 15:32
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

2 participants