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
Go binding: do not use pointer receiver for Close() #11383
Conversation
A mix of pointer/non-pointer receivers makes it impossible to use interfaces
@@ -345,7 +345,7 @@ func createDatabase(clusterFile string) (Database, error) { | |||
db := &database{outdb} | |||
runtime.SetFinalizer(db, (*database).destroy) | |||
|
|||
return Database{clusterFile, true, db}, nil | |||
return Database{clusterFile: clusterFile, isCached: true, database: db}, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is strictly unnecessary to fix the issue at hand but I found it helps in my IDE when looking for references of the fields.
Cc @johscheuer |
Result of foundationdb-pr-clang-ide on Linux CentOS 7
|
Result of foundationdb-pr-macos-m1 on macOS Ventura 13.x
|
Result of foundationdb-pr-cluster-tests on Linux CentOS 7
|
Result of foundationdb-pr-macos on macOS Ventura 13.x
|
Result of foundationdb-pr-clang on Linux CentOS 7
|
Result of foundationdb-pr on Linux CentOS 7
|
The error seems to be, while building a Docker image:
Unrelated? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Please hold merging this PR, I have found an unrelated issue in |
I have verified that calling
However for unknown reasons it does not crash if it is called 1-2 extra times, while it certainly crashes if we do that in a loop: --- a/bindings/go/src/fdb/fdb_test.go
+++ b/bindings/go/src/fdb/fdb_test.go
@@ -344,6 +344,11 @@ func TestDatabaseCloseRemovesResources(t *testing.T) {
if db == newDB {
t.Fatalf("Expected a different database object, got: %v and %v\n", db, newDB)
}
+
+ for i := 1; i < 1000; i++ {
+ fmt.Printf("closed %d times so far, going to close again\n", i)
+ db.Close()
+ }
}
func ExampleOpenWithConnectionString() { The above change will crash:
The reason I am looking into this is because I experience, randomly, a crash when using the @johscheuer no blocker to merge this PR but I might want to submit another one to fix this issue e.g. GC's call to I think the latter is the more idiomatic approach. |
Created PR here: #11394 |
A mix of pointer/non-pointer receivers makes it impossible to use interfaces for the
fdb.Database
type; I propose to change theClose()
method for consistency.See https://go.dev/play/p/PQ_FDXajpnB for an example of the problem (needs to be run locally):
Custom interfaces can still be used by using a pointer instead of directly the
fdb.Database
type:But that's less efficient.
NOTE: no test was updated
Code-Reviewer Section
The general pull request guidelines can be found here.
Please check each of the following things and check all boxes before accepting a PR.
For Release-Branches
If this PR is made against a release-branch, please also check the following:
release-branch
ormain
if this is the youngest branch)