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

Avatar store connection problems #127

Closed
daniloarcidiacono opened this issue Oct 2, 2022 · 1 comment · Fixed by #129
Closed

Avatar store connection problems #127

daniloarcidiacono opened this issue Oct 2, 2022 · 1 comment · Fixed by #129

Comments

@daniloarcidiacono
Copy link

daniloarcidiacono commented Oct 2, 2022

Hello, I'm trying to configure Remark42 to store avatars in MongoDB, but there are two problems:

  1. The mongodb+srv:// URIs are not recognized by NewStore:
func NewStore(uri string) (Store, error) {
        ....
	case strings.HasPrefix(uri, "mongodb://"), strings.HasPrefix(uri, "mongodb+srv://"): // <--- this is missing
        ....
}

just removing the +srv part results in connection failure:

2022/10/02 21:33:31.852 [PANIC] {cmd/server.go:315 cmd.(*ServerCommand).Execute} failed to setup application, failed to make avatar store: failed to connect to mongo server: server selection error: context deadline exceeded, current topology: { Type: Unknown, Servers: [{ Addr: cluster0.abcdef.mongodb.net:27017, Type: Unknown, Last error: connection() error occurred during connection handshake: dial tcp: lookup cluster0.abcdef.mongodb.net: no such host }, ] }

  1. The context timeout of just 1 second is too short:
func NewStore(uri string) (Store, error) {
        ....
	case strings.HasPrefix(uri, "mongodb://"), strings.HasPrefix(uri, "mongodb+srv://"):
                ...
                ctx, cancel := context.WithTimeout(context.Background(), time.Second)
        ....
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second)

resulting in

2022/10/02 22:17:18.812 [PANIC] {cmd/server.go:315 cmd.(*ServerCommand).Execute} failed to setup application, failed to make avatar store: failed to connect to mongo server: timed out while checking out a connection from connection pool: context deadline exceeded; maxPoolSize: 100, connections in use by cursors: 0, connections in use by transactions: 0, connections in use by other operations: 1

I modified the code on the fly by setting ctx, cancel := context.WithTimeout(context.Background(), 30 * time.Second) and it works.
Ideally the timeout should be configurable, MongoDB documentation reports a default timeout of 30 seconds.

Thanks

@paskal
Copy link
Collaborator

paskal commented Oct 2, 2022

@daniloarcidiacono, thanks a lot for your reports!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants