From 81096040e0cf19ed1ff1ef25739ab11b99e0a7c9 Mon Sep 17 00:00:00 2001 From: Mel Date: Fri, 8 Apr 2022 20:32:55 +0200 Subject: Graceful closing --- pkg/discord/gateway/gateway.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'pkg/discord/gateway') diff --git a/pkg/discord/gateway/gateway.go b/pkg/discord/gateway/gateway.go index 6fe0087..9c86bb6 100644 --- a/pkg/discord/gateway/gateway.go +++ b/pkg/discord/gateway/gateway.go @@ -76,7 +76,14 @@ func (g *GatewayImpl) Start(ctx context.Context, url string, token string) error } func (g *GatewayImpl) Close() error { - return g.conn.Close() + // Try closing gracefully. + g.logger.Debug().Msg("closing gateway gracefully...") + if err := g.conn.Close(1000); err != nil { + g.logger.Error().Err(err).Msg("error closing gateway gracefully, trying to murder...") + return g.conn.Kill() + } + + return nil } func (g *GatewayImpl) Heartbeat() error { -- cgit 1.4.1