[go: nahoru, domu]

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

Fix releasing not dead sock #2239

Merged
merged 3 commits into from
Oct 1, 2024

Conversation

EvgeniiMekhanik
Copy link
Contributor

When ss_connect fails we put socket refcounter
and release sock (when it becames equal to zero),
but socket was not closed. That leads to error
message in dmesg and some socket resources could
be not freed. This patch fix this behaviour, now
we close socket before free it.

@EvgeniiMekhanik EvgeniiMekhanik requested review from krizhanovsky and const-t and removed request for krizhanovsky September 11, 2024 12:39
@EvgeniiMekhanik EvgeniiMekhanik force-pushed the MekhanikEvgenii/fix-release-not-dead-sock branch from 74be1ef to 675c29b Compare September 11, 2024 12:40
Copy link
Contributor
@const-t const-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general LGTM, except cache initialization.

fw/cache.c Outdated Show resolved Hide resolved
Copy link
Contributor
@krizhanovsky krizhanovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a rework required in both the patches

fw/cache.c Outdated Show resolved Hide resolved
fw/sock_srv.c Outdated
@@ -277,6 +277,9 @@ tfw_sock_srv_connect_try(TfwSrvConn *srv_conn)
if (r != -ESHUTDOWN)
T_ERR("Unable to initiate a connect to server: %d\n",
r);
bh_lock_sock(sk);
ss_do_close(sk, 0);
bh_unlock_sock(sk);
sock_put(sk);
SS_CALL(connection_drop, sk);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not ss_close()? It calls also sock_put() and connection_drop. It's error prone and breaks the abstraction layers w/o a clear reason

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because here socket state is SS_CLOSE, but we should not call ss_do_close for socket in this state in all other places except here. We can add special flag for such socket, but I think that this solution is better

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand

Because here socket state is SS_CLOSE, but we should not call ss_do_close for socket in this state in all other places except here.

Yes, we discuss this particular place in tfw_sock_srv_connect_try().

My objection that here are 5 lines of code

		bh_lock_sock(sk);
		ss_do_close(sk, 0);
		bh_unlock_sock(sk);
		sock_put(sk);
		SS_CALL(connection_drop, sk);

dealing with low-level socket API - this is subject for sock.c, no sock_src.c, which should care about connection management and work with connection abstractions.

What would be wrong if we replace these 5 lines with ss_close()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look at the ss_tx_action case SS_CLOSE. we check that:

if (!((1 << sk->sk_state)
			      & (TCPF_ESTABLISHED | TCPF_SYN_SENT
				 | TCPF_CLOSE_WAIT)))

and if this if is true don't call ss_do_close. It is necessary to prevent multiple socket closing. But socket in tfw_sock_srv_connect_try has CLOSE state and this if is true. So if we call ss_close from tfw_sock_srv_connect_try instead of this five lines of code we never drop connection and close socket! We can pass special flag in ss_tx_action but I prefer this way. If you don't think so ok I will change it

@EvgeniiMekhanik EvgeniiMekhanik force-pushed the MekhanikEvgenii/fix-release-not-dead-sock branch 2 times, most recently from 82921fa to a33a0ca Compare September 26, 2024 09:31
Copy link
Contributor
@krizhanovsky krizhanovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but please do the fixes before the merge!

fw/cache.h Outdated Show resolved Hide resolved
fw/cache.c Outdated Show resolved Hide resolved
@EvgeniiMekhanik EvgeniiMekhanik force-pushed the MekhanikEvgenii/fix-release-not-dead-sock branch 4 times, most recently from 0beab74 to 2d33a7b Compare September 27, 2024 07:30
When `ss_connect` fails we put socket refcounter
and release sock (when it becames equal to zero),
but socket was not closed. That leads to error
message in dmesg and some socket resources could
be not freed. This patch fix this behaviour, now
we close socket before free it.
We allocate resources for cache if condition
`cache_cfg.cache || g_vhost->cache_purge` is true,
so we should dealloate it also if this condition
is true.
- Tempesta FW fails to start if cache directive is
empty or equal to zero, but purge directive is set.
- Tempesta FW fails to start if purge directive is
set but purge acl is not set and vice versa.
- Implement new function `ss_close_not_connected_socket`
to close sockets in TCP_CLOSE state (which are not DEAD),
to handle a situation when we create socket using
`ss_inet_create` in TCP_CLOSE state and need to close
such socket.
@EvgeniiMekhanik EvgeniiMekhanik force-pushed the MekhanikEvgenii/fix-release-not-dead-sock branch from 2d33a7b to 02380f5 Compare October 1, 2024 07:21
@krizhanovsky krizhanovsky merged commit 4647212 into master Oct 1, 2024
1 check failed
@krizhanovsky krizhanovsky deleted the MekhanikEvgenii/fix-release-not-dead-sock branch October 1, 2024 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants