#invoking a function while dropping a TCP connection of a client

6 messages · Page 1 of 1 (latest)

magic narwhal
#

I am trying to implement a service which will hold some value of an user and on dropping the TCP connection the data will be removed from the database.
I thought about using TTL on values, but it doesn't work because if the user tries to log in before the value is dropped then it causes a problem. And if the user stays idle for a long time while keeping the TCP connection the value will get automatically dropped due to TTL which will also cause a problem.

scenic ocean
#

hey! Couldn't you create a timestamp when the tcp connection is made and associate it to the user "session"
and manage it that way?

If the user reconnects the new timestamp will be different than the one you have associated to the data or on the
client "context". Would that make sense?

magic narwhal
scenic ocean
#

tying the cleanup to a TTL is very tricky, for example I'm a lazy person and I could be your user. what if your ttl is 2 minutes but i take 3 minutes? The server would think I'm "gone" when I'm not, it's a cat and mouse game between timeouts and real user behavior.
using the lifetime of the actual TCP connection is more reliable because it's tied to the real network state

magic narwhal