Skip to content

Commit

Permalink
Simulate network error / server shutting down
Browse files Browse the repository at this point in the history
Run server with:
while true ; do go run ./; done
  • Loading branch information
VojtechVitek committed Dec 8, 2023
1 parent 491ab99 commit eaa97da
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions _examples/golang-sse/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"log"
"log/slog"
"math/rand"
"sync"
Expand Down Expand Up @@ -60,6 +61,12 @@ func (s *ChatServer) SubscribeMessages(ctx context.Context, serverTimeoutSec int
case context.Canceled:
return fmt.Errorf("client disconnected")
default:
stream.Write(&proto.Message{
Id: uint64(rand.Uint64()),
AuthorName: "SERVER",
Text: "shutting down",
})
log.Fatal("FATAL")
return proto.ErrConnectionTooLong.WithCause(fmt.Errorf("timed out after %vs", serverTimeoutSec))
}

Expand Down

0 comments on commit eaa97da

Please sign in to comment.