Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: close db properly in early exit paths in ConnectToPostgres#18448

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
hugodutka wants to merge1 commit intomain
base:main
Choose a base branch
Loading
fromhugodutka/connect-to-postgres-close-db

Conversation

hugodutka
Copy link
Contributor

@hugodutkahugodutka commentedJun 19, 2025
edited
Loading

There were some code paths where if we exited early from the function the postgres connection would never get cleaned up.

This is the mechanism that cleans up the db - it requires the err variable to be not nil:

coder/cli/server.go

Lines 2319 to 2328 in118bf98

deferfunc() {
iferr==nil {
return
}
ifsqlDB!=nil {
_=sqlDB.Close()
sqlDB=nil
}
logger.Error(ctx,"connect to postgres failed",slog.Error(err))
}()

@hugodutkahugodutka changed the titlechore: close db properly on false version.Next in ConnectToPostgreschore: close db properly in early exit paths in ConnectToPostgresJun 19, 2025
@hugodutkahugodutkaforce-pushed thehugodutka/connect-to-postgres-close-db branch from471bd6d toe9f833bCompareJune 19, 2025 09:46
@hugodutkahugodutka marked this pull request as ready for reviewJune 19, 2025 10:36
@hugodutkahugodutka requested a review fromEmyrkJune 19, 2025 10:37
Comment on lines +2366 to +2367
err = xerrors.Errorf("no rows returned for version select: %w", version.Err())
return nil, err
Copy link
Member

Choose a reason for hiding this comment

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

Can we just name this error something else? LikedbError?

I say that because a few lines up isversion, err := sqlDB.QueryContext(ctx, "SHOW server_version_num;"). Does that not shadow theerr variable and break this assignment to the correcterr here?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@EmyrkEmyrkEmyrk left review comments

At least 1 approving review is required to merge this pull request.

Assignees

@hugodutkahugodutka

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@hugodutka@Emyrk

[8]ページ先頭

©2009-2025 Movatter.jp