ssbc / go-netwrap Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
I think you can set a deadline on net.Conn instances like conn.SetDeadline(time.Now().add(Duration{100000000}))
. The Go devs in their infinite wisdom make you call "SetDuration" over again every time there is a timeout error which is kind of dumb, but without any sort of timeout, I think every network operation that has a failure on the remote end leaves its goroutine hanging forever waiting for that dead connection to work again.
I noticed this trying out "go-ssb." When I left it running for a while, it accumulated a gigabyte of RAM doing basically nothing, and then when I killed the program, tens of thousands of identical error messages flooded the console, along the lines of "fetchFeed(%s:%d) gossip pump failed: %w"
in plugins/gossip/handler.go of go-ssb. Then I had to hard kill the program, getting just as many tens of thousands of stack traces from goroutines going belly up in the process. Many of them had been sitting idle for an hour. I think every time "gossip pump" fails, it just hangs the goroutine and leaves all that memory leaking out like a sieve, since there are no timeouts for network operations anywhere I can see.
In some cases you need to ioctl something on the filedescriptor or simply don't want to use std net.Dial
. ConnWrappers
only take effect after the fact the connection was opened. ioctl also doesn't work for the Serve()
case.
type Dialer interface{
Dial(net, addr string) (net.Conn, error)
}
func DialWithDialer(d Dialer, addr net.Addr, wrappers ...netwrap.ConnWrapper) (net.Conn, error) {
conn, err := d.Dial(addr.Network(), addr.String())
if err != nil {
return nil, errors.Wrap(err, "error dialing")
}
for _, cw := range wrappers {
conn, err = cw(conn)
if err != nil {
return nil, errors.Wrap(err, "error wrapping connection")
}
}
return conn, nil
}
I exported the Dialer func as a type in v0.0.2 as quick remedy but would like a more general solution.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.