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

fixes #454. Added DisconnectedErrCB to client #462

Merged
merged 3 commits into from
May 15, 2019

Conversation

mkorolyov
Copy link
Contributor

No description provided.

@coveralls
Copy link

coveralls commented May 14, 2019

Coverage Status

Coverage decreased (-0.1%) to 92.334% when pulling 9a2aafe on mkorolyov:disconnect_err into 4c154eb on nats-io:master.

Copy link
Member

@kozlovic kozlovic left a 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 contribution! I think it looks good, the only comments I would have are about the doc of the disconnected handlers.

nats.go Outdated
@@ -266,8 +269,15 @@ type Options struct {

// DisconnectedCB sets the disconnected handler that is called
// whenever the connection is disconnected.
// Will not be called if DisconnectedErrCB was initiated.
Copy link
Member

Choose a reason for hiding this comment

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

should it be: Will not be called if DisconnectedErrCB is set

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, fixed docs

nats.go Outdated
@@ -266,8 +269,15 @@ type Options struct {

// DisconnectedCB sets the disconnected handler that is called
// whenever the connection is disconnected.
// Will not be called if DisconnectedErrCB was initiated.
// DEPRECATED. use DisconnectedErrCB which passes initial err
Copy link
Member

Choose a reason for hiding this comment

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

which passes error that caused the disconnect event?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, fixed docs

nats.go Outdated
DisconnectedCB ConnHandler

// DisconnectedErrCB sets the disconnected error handler that is called
// whenever the connection is disconnected.
// DisconnectedCB will not be called if DisconnectedErrCB was initiated.
Copy link
Member

Choose a reason for hiding this comment

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

DisconnectedCB will not be called if DisconnectedErrCB is set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, fixed docs

nats.go Outdated
nc.ach.push(func() { nc.Opts.DisconnectedCB(nc) })
if nc.conn != nil {
if nc.Opts.DisconnectedErrCB != nil {
nc.ach.push(func() { nc.Opts.DisconnectedErrCB(nc, ErrConnectionClosed) })
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if maybe here we should use nil for the error instead of ErrConnectionClosed? That would mean that when calling nc.Close(), the disconnected callback is called but there is no error since it was called by the user.

Copy link
Member

Choose a reason for hiding this comment

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

Right. We should then add this to the "doc" of DisconnectedErrCB that it is possible to get nil as an error, one case would be when the user closes the connection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @wallyqs , thanks for review. Found possible missed case with err passing:
nats.go:1438 where we trying to initialize connected connection and got an err as result, if so we close connection with status DISCONNECTED. I think we should pass acquired error to new callback too, adding err as param to close() method? WDYT?
Adding err as param to close() will fix pointed issue when user closes connection, we will pass nil here with status CLOSED.

Copy link
Member

@wallyqs wallyqs May 14, 2019

Choose a reason for hiding this comment

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

I think that sounds good (thanks!)

nats.go Outdated
nc.ach.push(func() { nc.Opts.DisconnectedCB(nc) })
if nc.conn != nil {
if nc.Opts.DisconnectedErrCB != nil {
nc.ach.push(func() { nc.Opts.DisconnectedErrCB(nc, ErrConnectionClosed) })
Copy link
Member

Choose a reason for hiding this comment

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

Right. We should then add this to the "doc" of DisconnectedErrCB that it is possible to get nil as an error, one case would be when the user closes the connection.

@mkorolyov
Copy link
Contributor Author

@kozlovic @wallyqs Thanks for fast review! I've updated docs and added logic with proper err passing for close/disconnect status. Looks like it could be merged.

One thing i want to mention that i noticed blinking test TestRecvChanAsyncLeakGoRoutines, but it became green after another travis build. I didn't found any relation between changes i've made and that blinking test, could you pls take a look to make sure we are not breaking something under the hood? Thanks a lot!

Copy link
Member

@kozlovic kozlovic left a comment

Choose a reason for hiding this comment

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

Sorry, I would like a second pass on comments. After that I think we can merge. Thanks again for the contribution!

nats.go Outdated Show resolved Hide resolved
nats.go Outdated Show resolved Hide resolved
nats.go Outdated Show resolved Hide resolved
@kozlovic kozlovic merged commit 8318b38 into nats-io:master May 15, 2019
@mkorolyov mkorolyov deleted the disconnect_err branch May 16, 2019 08:04
@kozlovic
Copy link
Member

@mkorolyov I was getting ready to do a release and noticed that we missed some deprecated statements, but then I am having second thoughts. I wonder if we should not have named the handler type ConnErrHandler func(*Conn, error) instead of DisconnectErrHandler. The reason is that we could later on use that for other events that disconnect, so I would not want to limit ourselves (or have to add yet another handler). What do you think? I will submit a PR to see how that looks.

@mkorolyov
Copy link
Contributor Author

@mkorolyov I was getting ready to do a release and noticed that we missed some deprecated statements, but then I am having second thoughts. I wonder if we should not have named the handler type ConnErrHandler func(*Conn, error) instead of DisconnectErrHandler. The reason is that we could later on use that for other events that disconnect, so I would not want to limit ourselves (or have to add yet another handler). What do you think? I will submit a PR to see how that looks.

@kozlovic i can rename myself in PR, have some time at the moment :)

@kozlovic
Copy link
Member

Ok great!

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 this pull request may close these issues.

4 participants