Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Implement driver.Pinger #565

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

Closed
edsrzf wants to merge 3 commits into go-sql-driver:master from edsrzf:ping
Closed

Implement driver.Pinger #565

edsrzf wants to merge 3 commits into go-sql-driver:master from edsrzf:ping

Conversation

@edsrzf
Copy link

@edsrzf edsrzf commented Apr 2, 2017
edited
Loading

The Pinger interface was added in Go 1.8.

This implementation ignores the context parameter to Ping because wiring it in
would be a much larger change.

Fixes #505.

The Pinger interface was added in Go 1.8.
This implementation ignores the context parameter to Ping.
Copy link

But it seems useless and it may puzzle people who don't know that the ctx isn't used actually

Copy link
Author

edsrzf commented Apr 3, 2017

I don't think it's useless: there are cases where a connection to MySQL can be established, but it's not actually ready to start processing commands yet. I agree it's not ideal, but the work in #551 seems to have stalled. Probably because the pull request is so large.

This seems like a marginal improvement on what's there now, and it can be built upon. Let's start small.

)

func (mc *mysqlConn) Ping(ctx context.Context) error {
return mc.writeCommandPacket(comPing)
Copy link
Member

@methane methane Apr 3, 2017

Choose a reason for hiding this comment

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

https://dev.mysql.com/doc/internals/en/com-ping.html

You should read OK packet after send COM_PING.
Additionally, cancellation should be implemented too.
When Ping is cancelled between PING and OK, the connection should be disposed.

Copy link
Author

edsrzf commented Apr 4, 2017

Updated. Thanks for the review.

default:
}

_, err = mc.readResultOK()
Copy link
Member

@methane methane Apr 4, 2017

Choose a reason for hiding this comment

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

This code didn't cancel waiting OK package when ctx is canceled.

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure what you mean. Are you saying we should still read the OK result after the Done channel is closed? If so, what's the point if we're closing the connection anyway? And if not, please explain more.

Copy link
Member

@methane methane Apr 5, 2017

Choose a reason for hiding this comment

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

No. readResultOK() waits OK packet from MySQL server. It may take long time.
While waiting OK packet, context can be cancelled. Then, driver should abandon waiting OK.

Copy link
Author

@edsrzf edsrzf Apr 6, 2017
edited
Loading

Choose a reason for hiding this comment

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

So are you looking for something like this, then?

ch := make(chan err)
go func() {
 _, err = mc.readResultOK()
 ch <- err
}()
select {
case <-ctx.Done():
 mc.Close()
 return ctx.Err()
case err := <- ch:
 return err
}

caibirdme reacted with thumbs up emoji
Copy link
Member

@methane methane Apr 6, 2017

Choose a reason for hiding this comment

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

Yes

Copy link
Member

@methane methane Apr 6, 2017

Choose a reason for hiding this comment

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

Copy link
Author

edsrzf commented Apr 7, 2017

Updated again! Hopefully for the final time? 😀

go func() {
_, err := mc.readResultOK()
ch <- err
}()
Copy link
Member

@methane methane Apr 7, 2017

Choose a reason for hiding this comment

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

select {
case <-ctx.Done():
mc.netConn.SetReadDeadline(time.Now())
return ctx.Err()
Copy link
Member

@methane methane Apr 7, 2017

Choose a reason for hiding this comment

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

This is dangerous.

  • mc is not thread safe.
  • mc.readResultOK() is still working.
  • After Ping return, database/sql.DB will use this connection again. race may be happen.

Copy link
Member

methane commented Apr 7, 2017

I think mc.writeCommandPacket() and mc.readResultOK() should support context,
instead implementing cancellation in mc.Ping().

Please stop updating this pull request.
I need more time to think about internal design. Implementing context support is much harder
than people think.

Copy link
Author

edsrzf commented May 8, 2017

Seems clear that this is not a path forward. Closing.

@edsrzf edsrzf closed this May 8, 2017
@edsrzf edsrzf deleted the ping branch May 8, 2017 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@methane methane methane requested changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /