Changeset 138530 for trunk/base


Ignore:
Timestamp:
Jul 11, 2015, 11:14:59 AM (5 years ago)
Author:
cal@…
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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/src/darwintracelib1.0/darwintrace.c

    r136398 r138530  
    134134static char *filemap;
    135135
     136static void __darwintrace_sock_destructor(FILE *dtsock) {
     137        __darwintrace_close_sock = fileno(dtsock);
     138        fclose(dtsock);
     139        __darwintrace_close_sock = -1;
     140        pthread_setspecific(sock_key, NULL);
     141}
     142
    136143/**
    137144 * Setup method called as constructor to set up thread-local storage for the
     
    143150                abort();
    144151        }
    145         if (0 != (errno = pthread_key_create(&sock_key, NULL))) {
     152        if (0 != (errno = pthread_key_create(&sock_key, (void (*)(void *)) __darwintrace_sock_destructor))) {
    146153                perror("darwintrace: pthread_key_create");
    147154                abort();
Note: See TracChangeset for help on using the changeset viewer.