View Issue Details

IDProjectCategoryView StatusLast Update
0006273SOGoSOPEpublic2026-11-20 10:45
Reporterdl2ocb Assigned To 
PrioritynormalSeveritymajorReproducibilityalways
Status newResolutionopen 
Summary0006273: SOPE NGSieveClient: pre-STARTTLS buffered stream leak keeps sockets open after client destruction
Description

In SOPE 5.12.12, NGSieveClient's successful STARTTLS path replaces self->io without releasing the pre-TLS buffered stream. That stream retains the underlying socket. Releasing the client and draining its autorelease pool therefore leaves one TCP connection open per request.

Observed in SOGo: repeated use of the filter/preferences UI exhausted Dovecot's per-user/IP ManageSieve connection limit. activeExternalSieveScripts and preference saves then failed (HTTP 500/503, TRYLATER). STARTTLS itself succeeded; authenticated Sieve sessions could remain after browser logout.

Affected source: sope-mime/NGImap4/NGSieveClient.m, openConnection, successful STARTTLS branch. Tested with SOPE 5.12.12. The same relevant code was also found in tag SOPE-5.12.13 and master commit bc771afad3e49056d1e4c1f38edda17184684ffc during our source inspection; those versions were not runtime-tested. The tracker currently offers versions only up to 5.12.11, so Product Version is left blank rather than selecting an incorrect version.

Proposed minimal SOPE fix: insert [self->io release]; immediately before assigning the new TLS-backed NGBufferedStream, after [self->parser release]. The original socket is still held through previous_socket at this point. The attached patch is the exact patch used for the isolated test.

Explicit closeConnection avoids the remaining open TCP connection even in the original, explaining why callers that explicitly close do not show the same FD symptom. SOGo's activeExternalSieveScriptsAction path relied on client destruction in the inspected source.

Steps To Reproduce
  1. In a disposable Debian build environment, build original and patched SOPE 5.12.12 libraries from the same archive.
  2. Run the attached real-library Objective-C client against its loopback-only Python mock ManageSieve STARTTLS server (dummy credentials).
  3. Repeat 20 times: create a client, login (which performs STARTTLS), LISTSCRIPTS, release via its autorelease pool. Do not explicitly call closeConnection in the primary case.
  4. Confirm completed real NGSieveClient deallocations, then count socket FDs and independently count server-side open connections while the client OS process is still running. Process exit alone would hide the leak.
  5. Repeat with the patch, and with explicit closeConnection as a control for both builds.

Results (20 successful TLS/auth/LISTSCRIPTS cycles in every case):

  • Original, destruction only: 20 completed deallocations, 20 socket FDs, 20 server connections still open.
  • Patched, destruction only: 20 completed deallocations, 0 socket FDs, 0 server connections.
  • Original, explicit close: 20 completed deallocations, 0 socket FDs, 0 server connections.
  • Patched, explicit close: 20 completed deallocations, 0 socket FDs, 0 server connections.

All four processes returned 0; no mock-server errors. The observer overrides only dealloc and counts after the real superclass dealloc returns; networking/stream/socket implementations are not replaced.

See the attached source-only reproducer bundle for commands, exact sources, machine-readable results and the detailed report. The SOPE upstream archive is not bundled.

Additional Information

Test environment: Debian 13.7 x86_64, GNUstep Base 1.31.1-3, GNUstep Make 2.9.3-6, GCC/gobjc 14.2, OpenSSL development package 3.5.7.

SOPE-5.12.12.tar.gz SHA256: d5ff044fdb93aaffa77926d7fe1545368e1594de30a2779555bb78bb2edb1970
Original NGSieveClient.m SHA256: add864753c9822de1a8988b638999efbdcaba9502ee89af4adc8275308fef1d4
Patched NGSieveClient.m SHA256: ae6cac44ac999d33637e14b5082e5fcbb9763764e8eefbdbc8b25e9e6d59ce35

Separate practical check (2026-11-15): a locally built SOGo 5.12.12 image containing this SOPE patch plus additional explicit SOGo connection-close handling was deployed. Before and after three filter-open/save/leave cycles, doveadm who showed no sessions for the test account. The SOGo script was ACTIVE; the subject-based test rule was present, and the operator confirmed actual filtering of the instructed incoming test message. Raw message/delivery logs and individual HTTP results for every save were not collected. This practical check does not isolate the effect of the two changes; the compiled-library regression test above isolates the SOPE patch.

Limits: bounded 20-cycle-per-case SOPE test and a short user-confirmed integration check, not a long-duration, concurrency, reconnect/failure-matrix or general regression test. The loopback mock uses an ephemeral self-signed certificate; disabled certificate verification is limited to that disposable local test. No production TLS, timeout or connection-limit settings were relaxed. No real credentials are included.

TagsNo tags attached.

Activities

dl2ocb

dl2ocb

2026-11-20 10:45

reporter  

sope-starttls-stream-release-v1.0.0.patch (492 bytes)   
--- a/sope-mime/NGImap4/NGSieveClient.m
+++ b/sope-mime/NGImap4/NGSieveClient.m
@@ -332,6 +332,8 @@
 	      //[self->text release];
 	      [self->parser release];
 
+	      // Release the pre-TLS stream before replacing it; it retains the old socket.
+	      [self->io release];
 	      self->io = [(NGBufferedStream *)[NGBufferedStream alloc] initWithSource: self->socket];
 	      //self->text = [(NGCTextStream *)[NGCTextStream alloc] initWithSource: buffer];
 	      //[buffer release];

Issue History

Date Modified Username Field Change
2026-11-20 10:45 dl2ocb New Issue
2026-11-20 10:45 dl2ocb File Added: sope-starttls-stream-release-v1.0.0.patch
2026-11-20 10:45 dl2ocb File Added: sieve-starttls-reproducer-public-v1.0.0.zip