-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Pure Go SQLite #20614
Pure Go SQLite #20614
Conversation
Signed-off-by: jolheiser <[email protected]>
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.
How much is the binary size affected?
@@ -182,7 +179,7 @@ GOOS=linux GOARCH=arm64 make build | |||
Cross-build Gitea for Linux ARM64, with recommended build tags: | |||
|
|||
``` | |||
CC=aarch64-unknown-linux-gnu-gcc GOOS=linux GOARCH=arm64 TAGS="bindata sqlite sqlite_unlock_notify" make build | |||
CC=aarch64-unknown-linux-gnu-gcc GOOS=linux GOARCH=arm64 TAGS="bindata" make build |
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.
Also good to remove any reference to CGO? Like providing C profile here.
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.
If some users want to use some C modules like pam
, then CGO is still needed.
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.
I was under the impression the pam module didn't use CGO as well.
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.
Yes, we use https://github.com/msteinert/pam which is CGO 😔
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.
If some users want to use some C modules like
pam
, then CGO is still needed.
But there is a build tag for pam
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.
If some users want to use some C modules like
pam
, then CGO is still needed.But there is a build tag for pam
But this document is showing users how to set the C compiler if the CGO is needed when cross-build
On my machine it looks like it increased ~2mb EDIT: When I built the "old" version I forgot to use the |
Thanks @jolheiser, I closed mine. |
How about the performance for the new versions of sqlite compare with cgo sqlite. |
Signed-off-by: jolheiser <[email protected]>
Signed-off-by: jolheiser <[email protected]>
@@ -182,7 +179,7 @@ GOOS=linux GOARCH=arm64 make build | |||
Cross-build Gitea for Linux ARM64, with recommended build tags: | |||
|
|||
``` | |||
CC=aarch64-unknown-linux-gnu-gcc GOOS=linux GOARCH=arm64 TAGS="bindata sqlite sqlite_unlock_notify" make build | |||
CC=aarch64-unknown-linux-gnu-gcc GOOS=linux GOARCH=arm64 TAGS="bindata" make build |
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.
Since there is no CGO, so the CC
env could be removed?
Looks like sqlite doesn't support lock mechanism of c sqlite. We may need to post issues on upstream. |
Not sure, this is just how Go works. They are listening for when the provided ctx is cancelled, however in the meantime we are just changing the data of that context pointer. Solution is simple, avoid changing the context. |
I'll have to take a look at why we need to set those values/where they are being used. |
Because context is the only "variable" being shared across the |
Just to note this data race is not just in testing but also for actual workflow. So yeah giving a duplicated context and then cancel it after the function does resolve the data race: diff --git a/modules/ssh/ssh.go b/modules/ssh/ssh.go
index 8a280fb1b..31084870e 100644
--- a/modules/ssh/ssh.go
+++ b/modules/ssh/ssh.go
@@ -181,7 +181,11 @@ func publicKeyHandler(ctx ssh.Context, key ssh.PublicKey) bool {
// look for the exact principal
principalLoop:
for _, principal := range cert.ValidPrincipals {
- pkey, err := asymkey_model.SearchPublicKeyByContentExact(ctx, principal)
+ // Copy the context and give it a new done channel. This ensures that the read for context
+ // in sqlite3 is closed after we got the results and avoids a data race when we change the context.
+ dupCtx, cancel := context.WithCancel(ctx)
+ pkey, err := asymkey_model.SearchPublicKeyByContentExact(dupCtx, principal)
+ cancel()
if err != nil {
if asymkey_model.IsErrKeyNotExist(err) {
log.Debug("Principal Rejected: %s Unknown Principal: %s", ctx.RemoteAddr(), principal)
@@ -242,7 +246,11 @@ func publicKeyHandler(ctx ssh.Context, key ssh.PublicKey) bool {
log.Debug("Handle Public Key: %s Fingerprint: %s is not a certificate", ctx.RemoteAddr(), gossh.FingerprintSHA256(key))
}
- pkey, err := asymkey_model.SearchPublicKeyByContent(ctx, strings.TrimSpace(string(gossh.MarshalAuthorizedKey(key))))
+ // Copy the context and give it a new done channel. This ensures that the read for context
+ // in sqlite3 is closed after we got the results and avoids a data race when we change the context.
+ dupCtx, cancel := context.WithCancel(ctx)
+ pkey, err := asymkey_model.SearchPublicKeyByContent(dupCtx, strings.TrimSpace(string(gossh.MarshalAuthorizedKey(key))))
+ cancel()
if err != nil {
if asymkey_model.IsErrKeyNotExist(err) {
if log.IsWarn() { |
Signed-off-by: jolheiser <[email protected]>
Okay we're getting somewhere, so relevant issues:
Seems like xorm doesn't cover the
Seems like busy_timeout needs to be changed(maybe |
Related: #24658 |
And put my question here: Actually, I have somewhat objection for using that CCGO based sqlite package in Gitea Are we willing to take the risk of a complex essential core library getting unmaintained(some unfixable bugs)? Although SQLite is popular, but the pure-go solution isn't (actually, most people do not need the pure-go solution). I would still question whether it's worth to use CCGO in Gitea. What if there is an unfixable bug?
If CCGO pakcage has been proven to be stable enough, then I have no objection. |
As far as I'm aware, there is a As a side note: the I would personally enjoy having the pure-Go version, as it would be a step towards being able to |
IMO it's not related. With current CGO sqlite, |
I thought there was still a dependency on an old-fashioned way of embedding files in Go binaries, but I may have read incorrectly or be wrong. |
Yes, Dropping CGO would considerably simply our build because we can use the native go compiler, eliminating the xgo dependency. I would definitely prefer it. |
This should be replaced by #32628 |
This PR is an attempt at reviving #15002