Skip to content

libevent ioevent benchmark never closes its socketpairs #322

Description

@OneBucket126

Summary

All socketpairs are stored in pipes, but the benchmark reaches exit(0) without calling evutil_closesocket() for either endpoint.

Affected code

  • Repository commit: 477033f938fd47dfecde43c82257cd286d9fa38e
  • File: benchmark/ioevent/libevent/libevent_ioevent_bench.c
  • Original scanner location: line 189

Evidence

Source: benchmark/ioevent/libevent/libevent_ioevent_bench.c lines 175-194

 175: 
 176: 	events = calloc(num_pipes, sizeof(struct event));
 177: 	pipes = calloc(num_pipes * 2, sizeof(evutil_socket_t));
 178: 	if (events == NULL || pipes == NULL) {
 179: 		perror("malloc");
 180: 		exit(1);
 181: 	}
 182: 
 183: 	event_init();
 184: 
 185: 	for (cp = pipes, i = 0; i < num_pipes; i++, cp += 2) {
 186: #ifdef USE_PIPES
 187: 		if (pipe(cp) == -1) {
 188: #else
 189: 		if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, cp) == -1) {
 190: #endif
 191: 			perror("pipe");
 192: 			exit(1);
 193: 		}
 194: 	}

Source: benchmark/ioevent/libevent/libevent_ioevent_bench.c lines 196-208

 196:     long sum = 0;
 197: 	for (i = 0; i < 25; i++) {
 198: 		tv = run_once();
 199: 		if (tv == NULL)
 200: 			exit(1);
 201: 		fprintf(stdout, "%ld\n",
 202: 			tv->tv_sec * 1000000L + tv->tv_usec);
 203:         sum += tv->tv_sec * 1000000L + tv->tv_usec;
 204: 	}
 205:     fprintf(stdout, "%s Average : %ld\n", argv[0], sum/25);
 206: 
 207: 	exit(0);
 208: }

Impact

The default run leaves 200 descriptors open, and -n can make the leak large enough to hit descriptor limits during setup or wrapper-driven repeated runs.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions