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(kill): should not try to open a connection to a not running ReplSet #811

Merged
merged 1 commit into from
Oct 12, 2023

Conversation

arthursimas1
Copy link
Contributor

I've a situation where I listen to kill signals and execute .stop() when needed. The replica set has already been killed because the Ctrl + C signal is propagated to the whole process group, then I waits forever to connect and send a graceful shutdown.

@codecov
Copy link

codecov bot commented Oct 12, 2023

Codecov Report

Merging #811 (b58958a) into master (c1f2333) will increase coverage by 0.20%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #811      +/-   ##
==========================================
+ Coverage   90.94%   91.14%   +0.20%     
==========================================
  Files          15       15              
  Lines        1965     1965              
  Branches      494      494              
==========================================
+ Hits         1787     1791       +4     
+ Misses        169      165       -4     
  Partials        9        9              
Files Coverage Δ
...ngodb-memory-server-core/src/util/MongoInstance.ts 98.61% <100.00%> (+1.84%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

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

Looks good, though we should probably also add some options to the connection (like connectTimeoutMS which defaults to 30s)

@hasezoey hasezoey merged commit fefa869 into typegoose:master Oct 12, 2023
9 checks passed
@github-actions
Copy link

@github-actions github-actions bot added the released Pull Request released | Issue is fixed label Oct 12, 2023
@arthursimas1
Copy link
Contributor Author

hey @hasezoey.
I've tried the following options:

// 1)
con = await MongoClient.connect(uriTemplate(ip, port, 'admin'), {
  ...this.extraConnectionOptions,
  directConnection: true,
  socketTimeoutMS: 100,
  connectTimeoutMS: 100,
  waitQueueTimeoutMS: 100,
});

// 2)
con = await MongoClient.connect(uriTemplate(ip, port, 'admin'), {
  ...this.extraConnectionOptions,
  directConnection: true,
  serverSelectionTimeoutMS: 100,
});

Only the 2) case works. Right now I cannot think out of my head a test case for this alternative solution.

@arthursimas1
Copy link
Contributor Author

Testing some cases, it is possible that the server is killed between the isAlive assert and the connection. I agree that it's better to use the connection options. I'll send another PR.

@hasezoey
Copy link
Member

I agree that it's better to use the connection options. I'll send another PR.

no need to replace the change from the current PR, the options are only meant because it should not have much latency because it will always connect to localhost and so 30 second timeout is somewhat high

@arthursimas1 arthursimas1 deleted the fix-kill-repltset branch October 15, 2023 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement released Pull Request released | Issue is fixed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants