-
Notifications
You must be signed in to change notification settings - Fork 58
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
api: add context to connection create #333
api: add context to connection create #333
Conversation
bb488f6
to
ff7346d
Compare
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've expect that a
context
could be used with a network connection call. We could usenet.DialContext
instead ofnet.Dial
. - What do you thing about get rid of the
opts.Reconnect logic
with timeouts and retries inside theConnect()
? We could use just acontext
object to handle theConnect
lifetime and try to make the connection only once.
We are currently using Lines 201 to 212 in d8df65d
I don't think we can use context from |
We could remove and don't use the |
ff7346d
to
83a8e6f
Compare
NB: need to change go.mod and go.sum after the patch from |
4c4ac1c
to
e3e28fa
Compare
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.
The code is not the same as in the previous implementation. The previous implementation have a timeout by default. The current code have an infinity timeout.
So we need to use a context default timeout in all tests/examples/inner calls (or pass a context to it).
tarantool.Connect(context.Background(), server, opts)
5a79c7f
to
0d93a03
Compare
0d93a03
to
c85bfae
Compare
c85bfae
to
7364d75
Compare
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.
Thank you for the patch!
0c482a9
to
560f58d
Compare
560f58d
to
387460f
Compare
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.
Please, fix the problem and describe the fix/problem.
--- FAIL: TestAdd_CloseGraceful_concurrent (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x9a8cec]
goroutine 301 [running]:
testing.tRunner.func1(0xc000106400)
/opt/hostedtoolcache/go/1.13.15/x64/src/testing/testing.go:874 +0x69f
panic(0xbe5d60, 0x111eb00)
/opt/hostedtoolcache/go/1.13.15/x64/src/runtime/panic.go:679 +0x1b2
github.com/tarantool/go-tarantool/v2/pool.(*ConnectionPool).CloseGraceful(0xc00011e8c0, 0xc95140, 0xc000350520, 0xc00011e8c0)
/home/runner/work/go-tarantool/go-tarantool/pool/connection_pool.go:335 +0x13c
github.com/tarantool/go-tarantool/v2/pool_test.TestAdd_CloseGraceful_concurrent(0xc000106400)
/home/runner/work/go-tarantool/go-tarantool/pool/connection_pool_test.go:487 +0x44f
testing.tRunner(0xc000106400, 0xc95148)
/opt/hostedtoolcache/go/1.13.15/x64/src/testing/testing.go:909 +0x19a
created by testing.(*T).Run
/opt/hostedtoolcache/go/1.13.15/x64/src/testing/testing.go:960 +0x652
FAIL github.com/tarantool/go-tarantool/v2/pool 5.065s
Yeah, that happened because of this race:
So as a fix I did this: inside Note: there is no problem with |
`connection.Connect` and `pool.Connect` no longer return non-working connection objects. Those functions now accept context as their first arguments, which user may cancel in process. `connection.Connect` will block until either the working connection created (and returned), `opts.MaxReconnects` creation attempts were made (returns error) or the context is canceled by user (returns error too). Closes #136
387460f
to
b402c58
Compare
connection.Connect
andpool.Connect
no longer return non-working connection objects. Those functions now accept context as their first arguments, which user may cancel in process.connection.Connect
will block until either the working connection created (and returned),opts.MaxReconnects
creation attempts were made (returns error) or the context is canceled by user (returns error too).I didn't forget about (remove if it is not applicable):
Closes #136