]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Avoid creating connect netievents during low level failures in HTTP
authorArtem Boldariev <artem@boldariev.com>
Mon, 26 Apr 2021 19:52:59 +0000 (22:52 +0300)
committerArtem Boldariev <artem@boldariev.com>
Fri, 7 May 2021 12:47:24 +0000 (15:47 +0300)
This way we create less netievent objects, not bombarding NM with the
messages in case of numerous low-level errors (like too many open
files) in e.g. unit tests.

lib/isc/netmgr/http.c

index f82a7ae0201145c7d9305e369c4d8831bd8819c5..c2e403a5d023fc384560c54aa6cc62301b93189e 100644 (file)
@@ -1068,19 +1068,28 @@ http_call_connect_cb(isc_nmsocket_t *sock, isc_nm_http_session_t *session,
 
        REQUIRE(sock->connect_cb != NULL);
 
-       req = isc__nm_uvreq_get(sock->mgr, sock);
-       req->cb.connect = sock->connect_cb;
-       req->cbarg = sock->connect_cbarg;
-       if (session != NULL) {
-               session->client_httphandle = httphandle;
-               req->handle = NULL;
-               isc_nmhandle_attach(httphandle, &req->handle);
+       if (result == ISC_R_SUCCESS) {
+               req = isc__nm_uvreq_get(sock->mgr, sock);
+               req->cb.connect = sock->connect_cb;
+               req->cbarg = sock->connect_cbarg;
+               if (session != NULL) {
+                       session->client_httphandle = httphandle;
+                       req->handle = NULL;
+                       isc_nmhandle_attach(httphandle, &req->handle);
+               } else {
+                       req->handle = httphandle;
+               }
+
+               isc__nmsocket_clearcb(sock);
+               isc__nm_connectcb(sock, req, result, true);
        } else {
-               req->handle = httphandle;
-       }
+               void *cbarg = sock->connect_cbarg;
+               isc_nm_cb_t connect_cb = sock->connect_cb;
 
-       isc__nmsocket_clearcb(sock);
-       isc__nm_connectcb(sock, req, result, true);
+               isc__nmsocket_clearcb(sock);
+               connect_cb(httphandle, result, cbarg);
+               isc_nmhandle_detach(&httphandle);
+       }
 }
 
 static void
@@ -1168,6 +1177,7 @@ error:
                isc_mem_free(mctx, http_sock->h2.connect.uri);
        }
 
+       isc__nmsocket_prep_destroy(http_sock);
        isc__nmsocket_detach(&http_sock);
 }