-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
conn vs data cleanup #3442
conn vs data cleanup #3442
Conversation
b74e1f0
to
5c022f8
Compare
I think it will probably be a bit rocky regardless. As it is it looks fine to me however CI re Curl_connect create_conn does not always allocate for conn. |
Probably, yes. But I still think doing it gradually instead of a huge single merge will make a softer landing.
Clearly some more fixes are needed to make the builds green... |
a60166a
to
4dcc400
Compare
We use "conn" everywhere to be a pointer to the connection. Introduces two functions that "attaches" and "detaches" the connection to and from the transfer. Going forward, we should favour using "data->conn" (since a transfer always only has a single connection or none at all) to "conn->data" (since a connection can have none, one or many transfers associated with it and updating conn->data to be correct is error prone and a frequent reason for internal issues). Closes #3442
4dcc400
to
3abec02
Compare
We use "conn" everywhere to be a pointer to the connection. Introduces two functions that "attaches" and "detaches" the connection to and from the transfer. Going forward, we should favour using "data->conn" (since a transfer always only has a single connection or none at all) to "conn->data" (since a connection can have none, one or many transfers associated with it and updating conn->data to be correct is error prone and a frequent reason for internal issues). Side-effect: this also removes some old pipelining logic that isn't used and is destined for removal in April 2019 according to DEPRECATE.md. Closes #3442
We use "conn" everywhere to be a pointer to the connection. Introduces two functions that "attaches" and "detaches" the connection to and from the transfer. Going forward, we should favour using "data->conn" (since a transfer always only has a single connection or none at all) to "conn->data" (since a connection can have none, one or many transfers associated with it and updating conn->data to be correct is error prone and a frequent reason for internal issues). Side-effect: this also removes some old pipelining logic that isn't used and is destined for removal in April 2019 according to DEPRECATE.md. Closes #3442
3abec02
to
152a81e
Compare
Fixed the merge conflicts #3448 caused. |
- Split off connection shutdown procedure from Curl_disconnect into new function conn_shutdown. - Change the shutdown procedure to close the sockets before disassociating the transfer. Prior to this change the sockets were closed after disassociating the transfer so SOCKETFUNCTION wasn't called since they were closed. That likely came about from recent work started in Jan 2019 (curl#3442) to separate transfers from connections. Bug: https://curl.haxx.se/mail/lib-2019-02/0101.html Reported-by: Pavel Löbl Closes curl#3597 Closes #xxxx
- Split off connection shutdown procedure from Curl_disconnect into new function conn_shutdown. - Change the shutdown procedure to close the sockets before disassociating the transfer. Prior to this change the sockets were closed after disassociating the transfer so SOCKETFUNCTION wasn't called since they were closed. That likely came about from recent work started in Jan 2019 (curl#3442) to separate transfers from connections. Bug: https://curl.haxx.se/mail/lib-2019-02/0101.html Reported-by: Pavel Löbl Closes curl#3597 Closes #xxxx
- Split off connection shutdown procedure from Curl_disconnect into new function conn_shutdown. - Change the shutdown procedure to close the sockets before disassociating the transfer. Prior to this change the sockets were closed after disassociating the transfer so SOCKETFUNCTION wasn't called since the transfer was already disassociated. That likely came about from recent work started in Jan 2019 (#3442) to separate transfers from connections. Bug: https://curl.haxx.se/mail/lib-2019-02/0101.html Reported-by: Pavel Löbl Closes #3597 Closes #3598
Easy handles and connections
History
A common pattern in the libcurl code is having connections (struct
connectdata) point to its corresponding transfer (easy handle) using the
conn->data struct member.
We therefore pass around the 'conn' pointer only in a lot of places as we can
defer the transfer from it (using conn->data).
This made perfect sense back in the days when each transfer had a single
connection for the duration of a transfer and became less good when we added
Pipelining and downright ugly when we added support for multiplexed
connections.
Now, several simultaneous transfers can use the same connection so conn->data
has to be updated very frequently to make it accurate for every possible
situation. This is error-prone and is repeteadly a reason for issues and bugs.
Two transfers using two connections
Two transfers using one connection
A better way
A transfer however only uses a single connection for a transfer (or none at
all) at any given time. data->conn gets assigned when a connection is setup
and it gets cleared when the connection is again closed or returned to the
connection pool. Several transfers can point to the same connection while they
multiplex over the same one.
Going forward
Use of 'conn->data' should be removed over time in preference to 'data->conn'.
Function prototypes should rather work with
struct Curl_easy *data
as theidentifier poiting out the specific transfer and 'data->conn' to get the
connection (which then is NULL if there is no associated connection for this
transfer), rather than the old style that passes in
struct connectdata *conn
to most functions.
Curl_attach_connnection() - this is the new function that gets called when
a connection is "attached" to a transfer. When the two gets their
association. The association is then kept until detached at a later point.
Curl_detach_connnection() - this is the new function that gets called to
separate the tranfer from its associated connection. From this point on,
the transfer has no longer any associated connection.
Gradual, not single-shot
I previously made an attempt in making this change (basically removing
conn->data
) in a single shot, a single pull-request, but even before it wascompleted the changeset reached over 3000 modified lines. Quite simply too
large to be reviewable and landable in one atomic change.
That experience made me draw the conclusion that we need to make this change
gradually and over time.
Over time, data->conn should be used and conn->data use should be reduced.