Skip to content

Commit

Permalink
Add proper EOF return from route group's Read
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Dec 26, 2019
1 parent 5fe03b0 commit fceed7a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
12 changes: 10 additions & 2 deletions pkg/router/route_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,19 @@ func (rg *RouteGroup) Read(p []byte) (n int, err error) {
}
rg.mu.Unlock()

var data []byte
var (
data []byte
ok bool
)
select {
case <-rg.readDeadline.Wait():
return 0, timeoutError{}
case data = <-rg.readCh:
case data, ok = <-rg.readCh:
}

if !ok {
// route group got closed
return 0, io.EOF
}

rg.mu.Lock()
Expand Down
13 changes: 5 additions & 8 deletions pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,9 @@ func (r *router) handleDataPacket(ctx context.Context, packet routing.Packet) er
r.logger.Infof("Got new remote packet with route ID %d. Using rule: %s", packet.RouteID(), rule)
r.logger.Infof("Packet contents (len = %d): %v", len(packet.Payload()), packet.Payload())

if rg.isClosed() {
return io.ErrClosedPipe
}

rg.mu.Lock()
defer rg.mu.Unlock()
// TODO: test that it's not needed indeed
/*rg.mu.Lock()
defer rg.mu.Unlock()*/

select {
case <-rg.done:
Expand Down Expand Up @@ -425,12 +422,12 @@ func (r *router) handleClosePacket(ctx context.Context, packet routing.Packet) e
r.logger.Infof("Got new remote close packet with route ID %d. Using rule: %s", packet.RouteID(), rule)
r.logger.Infof("Packet contents (len = %d): %v", len(packet.Payload()), packet.Payload())

closeCode := routing.CloseCode(packet.Payload()[0])

if rg.isClosed() {
return io.ErrClosedPipe
}

closeCode := routing.CloseCode(packet.Payload()[0])

if err := rg.handleClosePacket(closeCode); err != nil {
return fmt.Errorf("error handling close packet with code %d by route group with descriptor %s: %w",
closeCode, &desc, err)
Expand Down

0 comments on commit fceed7a

Please sign in to comment.