-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
bug: return 0 instead of -1 when error occurred on a write #569
Conversation
c1298f7
to
6f153f8
Compare
I appreciate your effort here, but I don't think returning -1 is allowed, see io.WriterTo and io.Writer. If a |
The -1 is actually returning by gnet itself. type ProxyContext struct {
sync.Mutex
frontend gnet.Conn
backend gnet.Conn
}
func (f *Frontend) OnTraffic(c gnet.Conn) gnet.Action {
ctx := c.Context()
proxyContext, o := ctx.(*ProxyContext)
if !o || proxyContext == nil {
}
proxyContext.Lock()
n, err := c.WriteTo(proxyContext.backend)
if err != nil {
log.Println(err)
return gnet.Close
}
proxyContext.Unlock()
log.Println("frontend write", n)
return gnet.None
} The frontend is using gnet.Conn::WriteTo to write data to the backend server, but the backend server has already closed. And then It just raised panic. Line 152 in f5e5ef9
Line 364 in f5e5ef9
panic here because of the m is -1. Line 387 in f5e5ef9
At the same time, I found gnet.Conn::writev returns -1 too. Line 186 in f5e5ef9
Maybe I should change both of the -1 to 0. |
Returning -1 from a |
1a1bfa8
to
cb1207e
Compare
done |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #569 +/- ##
=======================================
Coverage 79.08% 79.08%
=======================================
Files 25 25
Lines 2109 2109
=======================================
Hits 1668 1668
Misses 305 305
Partials 136 136
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Thanks! |
fix panic in case error not nil. m gets -1 when writes to a closed connection