Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Charlotte
Sharkey
Commits
524ddb96
Commit
524ddb96
authored
5 months ago
by
Hazelnoot
Browse files
Options
Downloads
Patches
Plain Diff
fix race conditions in check_connect.js
parent
55df1ad1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/backend/scripts/check_connect.js
+39
-17
39 additions, 17 deletions
packages/backend/scripts/check_connect.js
with
39 additions
and
17 deletions
packages/backend/scripts/check_connect.js
+
39
−
17
View file @
524ddb96
...
...
@@ -12,27 +12,49 @@ const config = loadConfig();
// createPostgresDataSource handels primaries and replicas automatically.
// usually, it only opens connections first use, so we force it using
// .initialize()
createPostgresDataSource
(
config
)
.
initialize
()
.
then
(
c
=>
{
c
.
destroy
()
})
.
catch
(
e
=>
{
throw
e
}
);
async
function
connectToPostgres
(){
const
source
=
createPostgresDataSource
(
config
);
await
source
.
initialize
();
await
source
.
destroy
(
);
}
// Connect to all redis servers
function
connectToRedis
(
redisOptions
)
{
const
redis
=
new
Redis
(
redisOptions
);
redis
.
on
(
'
connect
'
,
()
=>
redis
.
disconnect
());
redis
.
on
(
'
error
'
,
(
e
)
=>
{
throw
e
;
async
function
connectToRedis
(
redisOptions
)
{
return
await
new
Promise
(
async
(
resolve
,
reject
)
=>
{
const
redis
=
new
Redis
({
...
redisOptions
,
lazyConnect
:
true
,
reconnectOnError
:
false
,
showFriendlyErrorStack
:
true
,
});
redis
.
on
(
'
error
'
,
e
=>
reject
(
e
));
try
{
await
redis
.
connect
();
resolve
();
}
catch
(
e
)
{
reject
(
e
);
}
finally
{
redis
.
disconnect
(
false
);
}
});
}
// If not all of these are defined, the default one gets reused.
// so we use a Set to only try connecting once to each **uniq** redis.
(
new
Set
([
config
.
redis
,
config
.
redisForPubsub
,
config
.
redisForJobQueue
,
config
.
redisForTimelines
,
config
.
redisForReactions
,
])).
forEach
(
connectToRedis
);
const
promises
=
Array
.
from
(
new
Set
([
config
.
redis
,
config
.
redisForPubsub
,
config
.
redisForJobQueue
,
config
.
redisForTimelines
,
config
.
redisForReactions
,
]))
.
map
(
connectToRedis
)
.
concat
([
connectToPostgres
()
]);
await
Promise
.
allSettled
(
promises
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment