-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
listeners: Use net.UDPConn instead #3999
Conversation
I think this should work. You could easily test it by just starting Caddy with HTTP/3 enabled. |
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.
Technically, I believe Packet sockets can be either UDP or IP networks: https://golang.org/pkg/net/#ListenPacket
The network must be "udp", "udp4", "udp6", "unixgram", or an IP transport. The IP transports are "ip", "ip4", or "ip6" followed by a colon and a literal protocol number or a protocol name, as in "ip:1" or "ip:icmp".
Although Caddy doesn't yet have a module that uses IP sockets, it could definitely happen (a layer 3 app, for example).
I wonder if we could either use a type-assertion to return the right fakeClose*
type (i.e. if a UDPConn, return a *fakeCloseUDPConn
, otherwise *fakeClosePacketConn
)? I'm just trying to not shut out future modules from IP listeners.
🤔 I'm not sure if I know how to resolve this, actually. The |
Ok -- no problem. I'll take a closer look as soon as I have a chance. |
I've implemented what I think is a much cleaner, flexible workaround -- though it is still a hack, it should work for 99.9% of use cases -- like so: func (fcpc fakeClosePacketConn) SetReadBuffer(bytes int) error {
switch conn := fcpc.PacketConn.(type) {
case *net.UDPConn:
return conn.SetReadBuffer(bytes)
case *net.IPConn:
return conn.SetReadBuffer(bytes)
case *net.UnixConn:
return conn.SetReadBuffer(bytes)
}
return fmt.Errorf("not implemented for %T", fcpc.PacketConn)
}
func (fcpc fakeClosePacketConn) SyscallConn() (syscall.RawConn, error) {
switch conn := fcpc.PacketConn.(type) {
case *net.UDPConn:
return conn.SyscallConn()
case *net.IPConn:
return conn.SyscallConn()
case *net.UnixConn:
return conn.SyscallConn()
}
return nil, fmt.Errorf("not implemented for %T", fcpc.PacketConn)
} I'm ready to commit and push this as it resolves the original warnings, but now I'm seeing this error produced from quic-go:
Any suggestions @marten-seemann ? |
By the way @marten-seemann, this error seems like a copy-paste mistake: https://github.com/lucas-clemente/quic-go/blob/6533c6f6e549979726581e7cd28e8f0c7e0213f1/packet_handler_map.go#L78 |
@mholt Thanks, I'll submit a fix. |
Thanks @marten-seemann ! What about the new error we're seeing though? Is it a problem? I feel like we're going to get bug reports. |
You should probably run the sysctl command to increase the buffer size, if you expect to receive larger amounts of data. |
@marten-seemann That is a GREAT idea, totally didn't think of that! Thanks! Got it down to this: func (fcpc fakeClosePacketConn) SetReadBuffer(bytes int) error {
if conn, ok := fcpc.PacketConn.(interface{ SetReadBuffer(int) error }); ok {
return conn.SetReadBuffer(bytes)
}
return fmt.Errorf("SetReadBuffer() not implemented for %T", fcpc.PacketConn)
}
func (fcpc fakeClosePacketConn) SyscallConn() (syscall.RawConn, error) {
if conn, ok := fcpc.PacketConn.(interface {
SyscallConn() (syscall.RawConn, error)
}); ok {
return conn.SyscallConn()
}
return nil, fmt.Errorf("SyscallConn() not implemented for %T", fcpc.PacketConn)
} And thanks for the tip, I'll refer anyone who asks about it to that system call then for their individual systems. |
Thanks for the initial contribution, Francis; closing in favor of ec3ac84. |
See #3998
How does this look @marten-seemann? Seems to compile, but untested.