[
https://issues.apache.org/jira/browse/CAMEL-27492?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
shashank updated CAMEL-27492:
-----------------------------
Fix Version/s: 4.25.0
> camel-smpp - a session lost while another reconnect still holds the lock is
> never reconnected, and a reconnect attempt that outlives a stop closes the
> session of the next start
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-27492
> URL: https://issues.apache.org/jira/browse/CAMEL-27492
> Project: Camel
> Issue Type: Bug
> Components: camel-smpp
> Reporter: shashank
> Assignee: shashank
> Priority: Major
> Fix For: 4.25.0
>
>
> h3. What happens
> *1. A reconnect request can be thrown away.* The session state listener runs
> {{reconnect()}}, which is guarded by {{tryLock()}}: when another thread holds
> the lock, the request is only logged ("could not acquire a lock for creating
> the session ...") and dropped. The thread that reported the previous lost
> session holds the lock while it waits for the reconnect task, also after the
> task bound the new session and before it unlocks. If the SMSC drops the new
> session in that window (an SMSC that closes right after {{bind_resp}}:
> restart, overload, too many binds), its listener clears the session and its
> request is dropped. The consumer stays {{Started}} with no session (or a
> closed one) and nothing reconnects it; the only trace is a WARN line. The
> producer has the same window around every holder of its {{connectLock}} (the
> reconnect, the eager start, a lazy session creation): every exchange then
> fails.
> *2. A reconnect attempt of a stopped start closes the session of the next
> one.* A stop waits 1 s for the reconnect service and then calls
> {{shutdownNow()}}, which does not interrupt a blocking connect (connect
> timeout = {{enquireLinkTimer}}, a proxy CONNECT without a read timeout).
> After a stop and a start of the same instance (suspend/resume, route
> restart), the old attempt fails late, and its catch block calls
> {{closeSession()}}, which closes the session in the field: the session of the
> new start. Its listener was removed first, so nothing reconnects; the
> consumer or producer stays started with no session.
> The listener also closes whatever session is in the field, not the session
> that reported.
> h3. How to reproduce
> An SMSC in the test JVM (jsmpp): (1) a hook on the thread that waits for the
> reconnect task, after the task bound session 2 and before the thread unlocks,
> makes the SMSC drop session 2: no further bind for 3 s with
> {{reconnectDelay=100}}, consumer {{Started}}, session null. Without a hook,
> an SMSC that accepts bind 2 and closes it at once left the consumer without a
> session in 4 to 19 of 30 runs. (2) a reconnect attempt held in an HTTP
> CONNECT proxy, then {{stop()}} and {{start()}}, then the proxy answers the
> old attempt with 502: the restarted session is closed, no further bind
> arrives.
> Found with a TLA+ model of the reconnect (see CAMEL-17859 for an earlier
> report of a reconnect lost to {{tryLock}}).
> h3. Fix
> * A reconnect request is never lost: it sets a flag before it tries the lock,
> and the thread that holds the lock looks at the flag again when it is done
> and runs another reconnect if the session is still closed.
> * Only the loss of the session in use asks for a reconnect: the listener
> closes the session that reported, and clears the field and reconnects only if
> the field holds that session. A session that was never set (a failed bind,
> which jsmpp reports on its reader thread when the SMSC closes the connection
> after its {{bind_resp}}) or that was replaced already asks for nothing, so a
> reconnect that gave up after {{maxReconnect}} is not started again by the
> binds it saw rejected.
> * A new session is set only while it is still bound, under the lock the
> listener takes; a session dropped before it is set fails the start, the lazy
> creation or the reconnect attempt (which tries again), as a failed bind does.
> * A reconnect belongs to the start it was requested in: every stop increments
> a generation; a reconnect attempt of an older generation ends, does not set
> its session (it closes it) and a failed attempt does not close the session in
> the field.
> * The producer runs the reconnect under its own lock; {{connectLock}} is
> taken only to set the new session, so the start and a lazy session creation
> finish first and keep their session.
> CAMEL-27090's behaviour (a stop releases the thread that waits for the
> reconnect) is kept.
> _Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)