mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-12-28 02:37:48 +00:00
properly fix the memory errors, it was caused by a function returning and PutBytes-ing a buffer before a worker had a chance to decrypt the buffer, so it would GetBytes the same buffer by dumb luck and then get an illegal overlap
This commit is contained in:
parent
01ea6d3d80
commit
5d323861f0
@ -199,7 +199,7 @@ func (c *Conn) Read(b []byte) (int, error) {
|
||||
}
|
||||
// Decrypt the packet
|
||||
bs, isOK := crypto.BoxOpen(&sinfo.sharedSesKey, p.Payload, &p.Nonce)
|
||||
defer util.PutBytes(bs)
|
||||
defer util.PutBytes(bs) // FIXME commenting this out leads to illegal buffer reuse, this implies there's a memory error somewhere and that this is just flooding things out of the finite pool of old slices that get reused
|
||||
// Check if we were unable to decrypt the packet for some reason and
|
||||
// return an error if we couldn't
|
||||
if !isOK {
|
||||
@ -223,11 +223,7 @@ func (c *Conn) Read(b []byte) (int, error) {
|
||||
case <-timer.C:
|
||||
return 0, ConnError{errors.New("Timeout"), true, false}
|
||||
}
|
||||
select { // Wait for worker to return
|
||||
case <-done:
|
||||
case <-timer.C:
|
||||
return 0, ConnError{errors.New("Timeout"), true, false}
|
||||
}
|
||||
<-done // Wait for the worker to finish, failing this can cause memory errors (util.[Get||Put]Bytes stuff)
|
||||
// Something went wrong in the session worker so abort
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@ -270,7 +266,6 @@ func (c *Conn) Write(b []byte) (bytesWritten int, err error) {
|
||||
return 0, errors.New("search failed")
|
||||
}
|
||||
}
|
||||
// defer util.PutBytes(b)
|
||||
var packet []byte
|
||||
done := make(chan struct{})
|
||||
workerFunc := func() {
|
||||
@ -294,11 +289,7 @@ func (c *Conn) Write(b []byte) (bytesWritten int, err error) {
|
||||
case <-timer.C:
|
||||
return 0, ConnError{errors.New("Timeout"), true, false}
|
||||
}
|
||||
select { // Wait for worker to return
|
||||
case <-done:
|
||||
case <-timer.C:
|
||||
return 0, ConnError{errors.New("Timeout"), true, false}
|
||||
}
|
||||
<-done // Wait for the worker to finish, failing this can cause memory errors (util.[Get||Put]Bytes stuff)
|
||||
// Give the packet to the router
|
||||
sinfo.core.router.out(packet)
|
||||
// Finally return the number of bytes we wrote
|
||||
|
@ -341,7 +341,7 @@ func (r *router) handleTraffic(packet []byte) {
|
||||
return
|
||||
}
|
||||
select {
|
||||
case sinfo.recv <- &p: // FIXME ideally this should be FIFO
|
||||
case sinfo.recv <- &p: // FIXME ideally this should be front drop
|
||||
default:
|
||||
util.PutBytes(p.Payload)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user