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

netlink: towards using the network poller in 1.12 #119

Closed
acln0 opened this issue Jan 16, 2019 · 3 comments
Closed

netlink: towards using the network poller in 1.12 #119

acln0 opened this issue Jan 16, 2019 · 3 comments

Comments

@acln0
Copy link
Collaborator

acln0 commented Jan 16, 2019

Hello.

This CL has landed, and will be included in Go 1.12. I think this opens an avenue for package netlink to make use of the poller.

I've investigated the code, and I believe the change can be made in a backwards-compatible manner, such that package netlink keeps working gracefully for < 1.12 users, and includes the new features for 1.12 and later.

In terms of changes to the public API of the package, no backwards incompatible changes would be made, but the set of patches would add SetDeadline, SetReadDeadline and SetWriteDeadline methods to Conn.

In terms of the internals of the package, making this change requires a pretty major refactor of the bits in conn_linux.go: sysSocket needs to change from using an integer file descriptor to an *os.File, and operations need to use syscall.RawConn when making system calls. A compatibility shim for pre-1.12 would also have to be written.

I am willing to commit to doing this work, provided that @mdlayher is open to the idea. I filed this bug in order to gauge interest, ask for a green light, and track progress.

Thanks,
Andrei

@mdlayher
Copy link
Owner

I'm totally on board with these changes, and honestly, I have no qualms making an immediate move to 1.12 and removing compatibility for any prior versions. Anybody who is concerned should already have the package vendored in their application.

Thanks again for doing this!

@acln0
Copy link
Collaborator Author

acln0 commented Jan 17, 2019

I have implemented most of the things described in the initial issue in this commit: acln0@2a82be3

The patch is not ready for review just yet, but I wanted to write a few lines about it, as a progress report, and to discuss some more specific details. The good news is that everything seems to be working as expected. The patch is still lacking some tests, but most of the changes I had in mind are there, so it's pretty close to what I envision its final form to be.

As for the actual topic of discussion: for now, I have kept the old behavior of the library for Go < 1.12, and introduced the new behavior for Go 1.12+. In my tree, both code paths use *os.File, but pre-1.12 code uses a blocking descriptor (and blocking calls), like it always has. I added the new deadline methods to Conn for all code, but they don't work on Go < 1.12.

If anyone wants to play with the code, note that it uses the "tip" build tag for now, because there is no Go 1.12 yet. This will change when 1.12 actually lands.

The build tags and file names I added are pretty ugly, but they are necessary if we want the code to keep building on < 1.12. I don't see a cleaner way to achieve backwards compatibility. @mdlayher, if these things are not too gross for you, I would propose that the package keep compatibility, at least for a while. Requiring a fresh new Go version seems a little harsh to me. I can commit to maintaining the compatibility code until we decide to pull the plug. I think the compatibility code is not a big deal, it's just a little ugly.

I'm going to send a PR when 1.12 lands, so we can test it with the actual released version of Go, and not from tip (which I find a little cumbersome). If all goes well, after this is reviewed, tested and merged, perhaps we should leave a note in golang/go#15021 that the new 1.12 features are indeed good enough to solve all the problems.

@mdlayher
Copy link
Owner

This all sounds reasonable to me. Thanks very much for your work on this so far.

@mdlayher mdlayher added this to the v1.0.0 milestone Feb 23, 2019
@mdlayher mdlayher closed this as completed Mar 1, 2019
ti-mo added a commit to ti-mo/conntrack that referenced this issue Dec 16, 2022
With the 'new' runtime poller introduced in Go 1.12, closing a Conn now
unblocks any blocked calls to netlink.Conn.Receive().

This patch handles closed Receive()s and introduces a WaitGroup to conntrack.Conn
that allows Conn.Close() to wait for all workers to exit.

See mdlayher/netlink#119.
ti-mo added a commit to ti-mo/conntrack that referenced this issue Dec 19, 2022
With the 'new' runtime poller introduced in Go 1.12, closing a Conn now
unblocks any blocked calls to netlink.Conn.Receive().

This patch handles closed Receive()s and introduces a WaitGroup to conntrack.Conn
that allows Conn.Close() to wait for all workers to exit.

See mdlayher/netlink#119.
ti-mo added a commit to ti-mo/conntrack that referenced this issue Dec 19, 2022
With the 'new' runtime poller introduced in Go 1.12, closing a Conn now
unblocks any blocked calls to netlink.Conn.Receive().

This patch handles closed Receive()s and introduces a WaitGroup to conntrack.Conn
that allows Conn.Close() to wait for all workers to exit.

See mdlayher/netlink#119.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants