[138530] trunk/base/src/darwintracelib1.0/darwintrace.c

cal at macports.org cal at macports.org
Sat Jul 11 04:14:59 PDT 2015


Revision: 138530
          https://trac.macports.org/changeset/138530
Author:   cal at macports.org
Date:     2015-07-11 04:14:59 -0700 (Sat, 11 Jul 2015)
Log Message:
-----------
base: darwintrace: close sockets when threads are terminated

If a long-running process started and terminated a large number of processes,
the file descriptors the were opened for these threads would not get closed.
Instead, they would linger around in memory, unreferenced, until the process
was terminated completely.

This can cause exhaustion of file descriptors and fail builds. I've seen this
behavior with GHC.

Modified Paths:
--------------
    trunk/base/src/darwintracelib1.0/darwintrace.c

Modified: trunk/base/src/darwintracelib1.0/darwintrace.c
===================================================================
--- trunk/base/src/darwintracelib1.0/darwintrace.c	2015-07-11 11:08:38 UTC (rev 138529)
+++ trunk/base/src/darwintracelib1.0/darwintrace.c	2015-07-11 11:14:59 UTC (rev 138530)
@@ -133,6 +133,13 @@
  */
 static char *filemap;
 
+static void __darwintrace_sock_destructor(FILE *dtsock) {
+	__darwintrace_close_sock = fileno(dtsock);
+	fclose(dtsock);
+	__darwintrace_close_sock = -1;
+	pthread_setspecific(sock_key, NULL);
+}
+
 /**
  * Setup method called as constructor to set up thread-local storage for the
  * thread id and the darwintrace socket.
@@ -142,7 +149,7 @@
 		perror("darwintrace: pthread_key_create");
 		abort();
 	}
-	if (0 != (errno = pthread_key_create(&sock_key, NULL))) {
+	if (0 != (errno = pthread_key_create(&sock_key, (void (*)(void *)) __darwintrace_sock_destructor))) {
 		perror("darwintrace: pthread_key_create");
 		abort();
 	}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20150711/d46a92ad/attachment.html>


More information about the macports-changes mailing list