[9.18] TLS Stream: backport connect callback handling behaviour from main
This commit contains the backport of the behaviour for handling TLS connect callbacks when wrapping up.
The current behaviour have not caused any problems to us, yet, but we are changing it to remain on the safer side.
Closes #3966 (closed)
Backport of MR !7724 (merged) (very partial)
Edited by Artem Boldariev