From ec237291b492c401f1bedca2b6d9bc107c380542 Mon Sep 17 00:00:00 2001 From: Nick Mills-Barrett Date: Thu, 29 Jan 2026 12:22:03 +0000 Subject: [PATCH] handlelinkedin: run disconnect calls in the background after error/logout These callbacks are called directly in the realtime connection loop, which itself blocks the disconnect call completing. --- pkg/connector/handlelinkedin.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/connector/handlelinkedin.go b/pkg/connector/handlelinkedin.go index 2fab6be..685ad55 100644 --- a/pkg/connector/handlelinkedin.go +++ b/pkg/connector/handlelinkedin.go @@ -30,7 +30,6 @@ func (l *LinkedInClient) onBadCredentials(ctx context.Context, err error) { Error: "linkedin-bad-credentials", Message: err.Error(), }) - l.Disconnect() if errors.Is(err, linkedingo.ErrTokenInvalidated) { l.userLogin.Metadata.(*UserLoginMetadata).Cookies.Clear() err = l.userLogin.Save(ctx) @@ -38,6 +37,8 @@ func (l *LinkedInClient) onBadCredentials(ctx context.Context, err error) { zerolog.Ctx(ctx).Err(err).Msg("failed to clear cookies after token invalidation") } } + // Disconnect in the background so we don't deadlock against the realtime loop which calls this + go l.Disconnect() } func (l *LinkedInClient) onUnknownError(ctx context.Context, err error) { @@ -48,7 +49,8 @@ func (l *LinkedInClient) onUnknownError(ctx context.Context, err error) { Message: err.Error(), }) // TODO probably don't do this unconditionally? - l.Disconnect() + // Disconnect in the background so we don't deadlock against the realtime loop which calls this + go l.Disconnect() } func (l *LinkedInClient) onDecoratedEvent(ctx context.Context, decoratedEvent *linkedingo.DecoratedEvent) {