Skip to content

Commit

Permalink
events: do call SetReadDeadline() in listen()
Browse files Browse the repository at this point in the history
In 6dc3797, a read deadline was added
so that listen() would not block forever on recv() calls when the
listener was closed. This was necessary because the event listener was
Close()'d by cancelling a context. If recv() was blocking, the loop
would not ever notice the closed context.

In the current logic, Close() will call el.conn.Close(), which will
cause any blocking recv() call to return io.EOF, thus closing the event
loop as expected. Therefore, the read deadline is no longer necessary.

Related: #34

Signed-off-by: Nick Rosbrook <nr@enr0n.net>
  • Loading branch information
enr0n committed Jun 10, 2021
1 parent d41166f commit 03eb555
Showing 1 changed file with 0 additions and 10 deletions.
10 changes: 0 additions & 10 deletions vici/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"errors"
"fmt"
"io"
"net"
"sync"
"time"
)
Expand Down Expand Up @@ -124,17 +123,8 @@ func (el *eventListener) listen() {
// Try to read a packet...
}

// Set a read deadline so that this loop can continue
// at a reasonable pace. If the error is a timeout,
// do not send it on the event channel.
_ = el.conn.SetReadDeadline(time.Now().Add(500 * time.Millisecond))

p, err := el.recv()
if err != nil {
if ne, ok := err.(net.Error); ok && ne.Timeout() {
continue
}

// If there is an error already buffered, that means there
// was no eventTransportCommunicate caller to read it. The
// buffer size is only 1, so flush before writing.
Expand Down

0 comments on commit 03eb555

Please sign in to comment.