Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue when using UNIX socket: Connection #0 is still name resolving, can't reuse #9664

Closed
vasiliy-ul opened this issue Oct 7, 2022 · 4 comments

Comments

@vasiliy-ul
Copy link

vasiliy-ul commented Oct 7, 2022

Hello. I observe an issue while running some tests that use curl with a unix socket: https://gitlab.com/nbdkit/nbdkit/-/blob/master/tests/test-curl-header-script.c

The tests trigger several HTTP requests. The first one goes well:

nbdkit: debug: curl: load
nbdkit: debug: curl: config key=url, value=http://localhost/disk
nbdkit: debug: curl: config key=header-script, value=if [ $iteration -eq 0 ]; then echo X-Test: hello; fi
echo X-Iteration: $iteration
echo 'X-Empty;'

nbdkit: debug: curl: config key=header-script-renew, value=1
nbdkit: debug: curl: config key=unix-socket-path, value=/tmp/wswOJAjw/sock
nbdkit: debug: curl: config_complete
nbdkit: debug: using thread model: serialize_requests
nbdkit: debug: curl: get_ready
nbdkit: debug: curl: after_fork
nbdkit: curl: debug: curl: preconnect
nbdkit: curl: debug: newstyle negotiation: flags: global 0x3
nbdkit: curl: debug: newstyle negotiation: client flags: 0x3
nbdkit: curl: debug: newstyle negotiation: NBD_OPT_STRUCTURED_REPLY: client requested structured replies
nbdkit: curl: debug: newstyle negotiation: NBD_OPT_GO: client requested export ''
nbdkit: curl: debug: curl: open readonly=0 exportname="" tls=0
nbdkit: curl: debug: curl: default_export readonly=0 tls=0
nbdkit: curl: debug: curl: running header-script
nbdkit: curl: debug: header-script returned 3 header(s)
nbdkit: curl: debug:   Trying /tmp/wswOJAjw/sock:0...
nbdkit: curl: debug: Connected to localhost () port 80 (#0)
nbdkit: curl: debug: C: HEAD /disk HTTP/1.1

while on the second I see error message Connection #0 is still name resolving, can't reuse:

nbdkit: curl: debug: Mark bundle as not supporting multiuse
nbdkit: curl: debug: S: HTTP/1.1 200 OK
nbdkit: curl: debug: S: Accept-rANGES:     bytes
nbdkit: curl: debug: S: Connection: keep-alive
nbdkit: curl: debug: S: Content-Type: application/octet-stream
nbdkit: curl: debug: S: Content-Length: 105923072
nbdkit: curl: debug: S: 
nbdkit: curl: debug: Connection #0 to host localhost left intact
nbdkit: curl: debug: content length: 105923072
nbdkit: curl: debug: accept range supported (for HTTP/HTTPS)
nbdkit: curl: debug: curl: open returned handle 0x55fe754678c0
nbdkit: curl: debug: curl: prepare readonly=0
nbdkit: curl: debug: curl: get_size
nbdkit: curl: debug: curl: can_write
nbdkit: curl: debug: curl: can_zero
nbdkit: curl: debug: curl: can_fast_zero
nbdkit: curl: debug: curl: can_trim
nbdkit: curl: debug: curl: can_fua
nbdkit: curl: debug: curl: can_flush
nbdkit: curl: debug: curl: is_rotational
nbdkit: curl: debug: curl: can_multi_conn
nbdkit: curl: debug: curl: can_cache
nbdkit: curl: debug: curl: can_extents
nbdkit: curl: debug: newstyle negotiation: flags: export 0x8c1
nbdkit: curl: debug: curl: block_size
nbdkit: curl: debug: newstyle negotiation: NBD_OPT_GO: NBD_INFO_BLOCK_SIZE: client requested but no plugin or filter provided block size information, ignoring client request
nbdkit: curl: debug: handshake complete, processing requests serially
nbdkit: curl: debug: curl: pread count=512 offset=0
nbdkit: curl: debug: curl: running header-script
nbdkit: curl: debug: header-script returned 2 header(s)
nbdkit: curl: debug: Found bundle for host: 0x55fe75469050 [serially]
nbdkit: curl: debug: Can not multiplex, even if we wanted to
nbdkit: curl: debug: Connection #0 is still name resolving, can't reuse
nbdkit: curl: debug:   Trying /tmp/wswOJAjw/sock:0...
nbdkit: curl: debug: Connected to localhost () port 80 (#1)
nbdkit: curl: debug: C: GET /disk HTTP/1.1

This eventually causes problems with the test execution. I can reproduce this with libcurl 7.85.0.

After running with a couple of previous versions, eventually I was able to bisect the commit 0f23341.

I am very new to the curl codebase, but it seems to me that after the mentioned change, the primay_ip field is not properly updated anymore when UNIX sockets are used:

curl/lib/url.c

Lines 1253 to 1258 in 83de62b

if(!check->primary_ip[0]) {
infof(data,
"Connection #%ld is still name resolving, can't reuse",
check->connection_id);
continue;
}

Also in the log, the output of Curl_verboseconnect is Connected to localhost () port 80 (#1) and here the primary_ip is empty as well (in ()).

I was able to fix the problem with the bellow patch by handling the newly introduced TRNSPRT_UNIX in Curl_updateconninfo:

diff --git a/lib/connect.c b/lib/connect.c
index c1d8cfd39..d830c00fc 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -774,6 +774,11 @@ void Curl_updateconninfo(struct Curl_easy *data, struct connectdata *conn,
     Curl_conninfo_local(data, sockfd, local_ip, &local_port);
   }
 #endif
+  else if(conn->transport == TRNSPRT_UNIX) {
+    if(!conn->bits.reuse)
+      Curl_conninfo_remote(data, conn, sockfd);
+    Curl_conninfo_local(data, sockfd, local_ip, &local_port);
+  }
 
   /* persist connection info in session handle */
   Curl_persistconninfo(data, conn, local_ip, local_port);

I just wanted to share the patch and get some feedback. Would that be a proper way to fix the issue?

I did this

I expected the following

curl/libcurl version

[curl -V output]

operating system

@bagder
Copy link
Member

bagder commented Oct 7, 2022

Thanks for the report and the patch. I think it can be simplified somewhat. Let me make an attempt in a PR that you can test...

bagder added a commit that referenced this issue Oct 7, 2022
Reported-by: Vasiliy Ulyanov
Fixes #9664
@bagder
Copy link
Member

bagder commented Oct 7, 2022

Try #9670!

bagder added a commit that referenced this issue Oct 7, 2022
Reported-by: Vasiliy Ulyanov
Fixes #9664
Closes #9670
@vasiliy-ul
Copy link
Author

vasiliy-ul commented Oct 7, 2022

Try #9670!

Works fine:

nbdkit: curl: debug: Re-using existing connection #0 with host localhost
nbdkit: curl: debug: Connected to localhost (/tmp/wsUh9Vjj/sock) port 80 (#0)
nbdkit: curl: debug: C: GET /disk HTTP/1.1

@bagder bagder closed this as completed in 4232e1a Oct 8, 2022
@vasiliy-ul
Copy link
Author

vasiliy-ul commented Oct 8, 2022

Thanks for taking care of that!

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

Successfully merging a pull request may close this issue.

2 participants