Connections hang in SSL negotiation when GssEncryptionMode=Prefer (default) on Linux without Kerberos, causing OOM

Aperta
#6,524 12 commenti 2 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 6 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
csharp, postgresql
Ambito
databases

Direzione di ricerca

Start by tracing the reported path from ConnectAsync through RawOpen, NegotiateEncryption, SetupEncryption, and SslStream.ForceAuthenticationAsync; reproduce on Alpine Linux without Kerberos with the default GssEncryptionMode. Done means connections complete or fail cleanly instead of hanging and accumulating, while GssEncryptionMode=Disable remains only the reported workaround.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

After upgrading to Npgsql 10, services running on Alpine Linux containers (without Kerberos) experience a memory leak that leads to OOM kills. The root cause is the new default GssEncryptionMode=Prefer — Npgsql 10 attempts GSSAPI negotiation on every new connection, and on Linux without libgssapi_krb5.so.2, connections hang indefinitely during the SSL fallback.

Environment

  • Npgsql version: 10.0.2 (pulled transitively via Npgsql.OpenTelemetry 10.0.2)
  • Previous Npgsql version: 9.0.4 (unaffected)
  • Runtime: .NET 9, Alpine Linux containers
  • GssEncryptionMode: not set (default Prefer)

Observed behavior

Connections get stuck permanently at:

ConnectAsync → RawOpen → NegotiateEncryption → SetupEncryption → SslStream.ForceAuthenticationAsync

Heap analysis with dotnet-dump showed:

  • 70 NpgsqlConnector instances accumulating in ~29 minutes
  • GC roots tracing through Timer → TimerCallback → ... → SslStream.ForceAuthenticationAsync
  • Connections are never completed, never disposed, never GC'd

Memory growth is continuous and eventually causes OOM kills in Kubernetes.

Expected behavior

On systems without Kerberos, GSSAPI negotiation should fail fast and fall back gracefully — connections should complete or fail cleanly, not hang indefinitely.

Workaround

Adding GssEncryptionMode=Disable to the connection string resolves the issue completely. Memory stabilizes immediately. Confirmed in multiple production services.

Comparison with Npgsql 9.x

Npgsql 9.0.4 (no GSSAPI support) does not exhibit this behavior — connections complete successfully.

Additional context

Discovered while investigating OOM kills across multiple Kubernetes services after an unintentional upgrade to Npgsql 10 via Npgsql.OpenTelemetry 10.0.2. The hang only occurs on Linux without Kerberos and is fully reproducible.

Lingua principale
C#
Stelle
3.7k
Fork
890
Merge medio
4g 11h
PR unite (30g)
19

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

  • Nessun Dockerfile né file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di npgsql/npgsql

Tutte le issue di npgsql/npgsql

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.