Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

methodTsmCustomTLSInternalServer.NotifyLock

class procedure NotifyLock; static;
SERIALISES MUTATION OF A SHARED ENGINE'S FREE-NOTIFICATION LIST.

TComponent.FreeNotification is RECIPROCAL and unsynchronised: it adds to the notified component's FFreeNotifies AND to the notifier's, and RemoveFreeNotification / RemoveFreeNotifications (which TComponent.Destroy calls) do the same in reverse. That is a plain TList<TComponent> with no lock of its own.

ONE ENGINE SERVING SEVERAL THREADS IS THE SHIPPED ARRANGEMENT, not an abuse of it: tSmtpSmarthostAgent builds a client per delivery and tSmtpSpool runs deliveries on DeliveryThreads worker threads, every one of them pointing its client at the same engine. Each such client registers on attach and deregisters as it dies, so N threads mutate this component's FFreeNotifies concurrently. Measured consequence: the list is corrupted, and what faults is this component's own teardown, walking it from RemoveFreeNotifications - an access violation, or a call through a list slot that no longer holds a component at all.

So every mutation this library makes goes through here. It is a PROCESS-WIDE lock because the reciprocal walk reaches both components and can start from either; it is taken only on attach, detach and teardown - never on a data path - so it costs one uncontended acquire per delivery. Recursive, because a notification handler reached under it can come straight back (a client's Notification nils its engine reference).