azure-webjobs-sdk icon indicating copy to clipboard operation
azure-webjobs-sdk copied to clipboard

SingletonListener releases lease before stopping the inner listener

Open vit-svoboda opened this issue 3 years ago • 1 comments

The SingletonListener implementation of IListener may lead an uneducated observer to believe the inner listener is only executed as a singleton, i.e. is running only as long as the lock lease is being held.

  1. First the lock lease is acquired, see the source.
  2. Then the inner listener is started, see the source.

However, when during the shutdown, the order remains the same, leaving a bit of inner listener run after the lock is no longer leased.

  1. First release lock lease, see the source
  2. Then the inner listener is stopped, see the source.

Expected behavior

I'd expect the SingletonListener first stop the inner listener and only after that release the lock.

Actual behavior

The inner listener may run after the lock has been release and another singleton listener instance acquired the lock and started its own inner listener. As far as I can tell, it's always been like this, both v2 and v3.

Is that on purpose? I managed to deal with it in my own code, but I must say I find the behaviour quite surprising.

vit-svoboda avatar Feb 03 '22 13:02 vit-svoboda

Tagging @fabiocav for triage.

pragnagopa avatar Feb 03 '22 17:02 pragnagopa

Appears to have been fixed in https://github.com/Azure/azure-webjobs-sdk/pull/2898, so it was not in fact intentional!

vit-svoboda avatar Feb 27 '23 14:02 vit-svoboda