private void tryImmediateDelivery()
    {
        final List<Deliverable> deliverables = drainPendingElements();
        if (deliverables.isEmpty()) {
            Log.trace("Immediate delivery of pending data to the client on session {} was requested, but no data is pending.", getStreamID());
            return;
        }

        // OF-2445: stanzas should not linger forever in a queue of a session that is already closed.
        if (isClosed()) {
            deliverables.forEach(deliverable -> failDelivery(deliverable.getPackets()));
            return;
        }

        final Optional<HttpConnection> connection = getConnectionReadyForOutboundDelivery();

        if (connection.isEmpty()) {
            Log.trace("Immediate delivery of pending data to the client on session {} was requested, but no connection is available. The data ({} deliverables) will be re-queued.", getStreamID(), deliverables.size());
            // place pending deliverables back on queue. // FIXME: if other threads have placed pending elements, this will cause a re-order, which might be undesirable.
            pendingElements.addAll(deliverables);
            return;
        }

        // OF-2444: deliver asynchronously, to avoid deadlocking issues.
        HttpBindManager.getInstance().getSessionManager().execute(this, () -> {
            try {
                Log.trace("Stream {}: Immediate delivery of {} deliverable(s)", streamID, deliverables.size());
                deliver(connection.get(), deliverables, true);
            } catch (HttpConnectionClosedException e) {
                /* Connection was closed, try the next one. Indicates a (concurrency?) bug. */
                Log.warn("Iterating over a connection that was closed for session {}. Openfire will recover from this problem, but it should not occur in the first place.", getStreamID(), e);
                // place pending deliverables back on queue. // FIXME: if other threads have placed pending elements, this will cause a re-order, which might be undesirable.
                pendingElements.addAll(deliverables);
            } catch (IOException e) {
                Log.warn("An unexpected exception occurred while iterating over connections for session {}. Openfire will attempt to recover by ignoring this connection.", getStreamID(), e);
                // place pending deliverables back on queue. // FIXME: if other threads have placed pending elements, this will cause a re-order, which might be undesirable.
                pendingElements.addAll(deliverables);
            }
        });
    }
Tries to deliver all data that is queued to be sent to the client, if data has been queued and a connection is
available for delivery.

When no data is queued for delivery, or when no connection is available, an invocation does nothing.
xmppserver/src/main/java/org/jivesoftware/openfire/http/HttpSession.java