Skip to content

gremlin-go: fix deadlock on (*DriverRemoteConnection).Close#1754

Merged
spmallette merged 2 commits into
apache:3.5-devfrom
jroimartin:fix-pr-1734
Jul 15, 2022
Merged

gremlin-go: fix deadlock on (*DriverRemoteConnection).Close#1754
spmallette merged 2 commits into
apache:3.5-devfrom
jroimartin:fix-pr-1734

Conversation

@jroimartin
Copy link
Copy Markdown
Contributor

@jroimartin jroimartin commented Jul 12, 2022

Further analysis shows that #1734 is not the right fix. A deadlock can still happen in (*gremlinServerWSProtocol).readLoop if errorCallback is called before the connection protocol is closed and, because of this, (*gremlinServerWSProtocol).close calls (*gremlinServerWSProtocol).wg.Wait.

This commit adds the parameter "wait" to protocol.close. So, the call to (*gremlinServerWSProtocol).wg.Wait can be skipped when called from within an error callback. Also, the test that was introduced has been updated.

@jroimartin
Copy link
Copy Markdown
Contributor Author

@simonz-bq @lyndonbauto you might want to give this one a look because you already have the context of #1734. Thanks!

Further analysis shows that apache#1734 is not the right fix. A
deadlock can still happen in (*gremlinServerWSProtocol).readLoop if
errorCallback is called before the connection protocol is closed and, because
of this, (*gremlinServerWSProtocol).close calls
(*gremlinServerWSProtocol).wg.Wait.

This commit adds the parameter "wait" to protocol.close. So, the call to
(*gremlinServerWSProtocol).wg.Wait can be skipped when called from within an
error callback. Also, the test that was introduced has been updated.
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jul 12, 2022

Codecov Report

❌ Patch coverage is 80.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.58%. Comparing base (92560d9) to head (c93661f).
⚠️ Report is 451 commits behind head on 3.5-dev.

Files with missing lines Patch % Lines
gremlin-go/driver/connection.go 20.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           3.5-dev    #1754      +/-   ##
===========================================
+ Coverage    63.48%   63.58%   +0.09%     
===========================================
  Files           23       23              
  Lines         3640     3636       -4     
===========================================
+ Hits          2311     2312       +1     
+ Misses        1150     1145       -5     
  Partials       179      179              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@simonz-bq
Copy link
Copy Markdown
Contributor

simonz-bq commented Jul 13, 2022

Edit: nvm overall lgtm +1

Minor suggestion in the changes

err := connection.protocol.close()
if err != nil {

// This callback is called from within protocol.readLoop. Therefore,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we modify protocol.readLoop?

Simply I would just like all protocol.wg.Done() to be removed, and instead added before the for as defer(protocol.wg.Done().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure thing. Done in c93661f. I did the same in transporter.writeLoop.

Copy link
Copy Markdown
Contributor

@simonz-bq simonz-bq left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@spmallette spmallette merged commit 986f518 into apache:3.5-dev Jul 15, 2022
@jroimartin jroimartin deleted the fix-pr-1734 branch July 21, 2022 20:54
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.

4 participants