malamute icon indicating copy to clipboard operation
malamute copied to clipboard

Client not disconnecting from server when the program is interrupted

Open dharanikumar-s opened this issue 8 years ago • 2 comments

Hi, In mlm_client_destroyfunction, mlm_client_destructorwill not be called when zsys_interruptedoccurs. Is it by design, not to disconnect from the server when an interrupt occurs? could you explain the reason behind it? Thank you.

void
mlm_client_destroy (mlm_client_t **self_p)
{
    assert (self_p);
    if (*self_p) {
        mlm_client_t *self = *self_p;
        if (self->actor && !zsys_interrupted) {
            //  Before destroying the actor we have to flush any pending
            //  traffic on the msgpipe, otherwise it gets lost in a fire and
            //  forget scenario. We do this by sending $FLUSH to the msgpipe
            //  and waiting for a signal back on the cmdpipe.
            if (zstr_send (self->msgpipe, "$FLUSH") == 0)
                zsock_wait (self->actor);
            mlm_client_destructor (self);
        }
        zactor_destroy (&self->actor);
        zsock_destroy (&self->msgpipe);
        zstr_free (&self->command);
        zstr_free (&self->reason);
        free (self);
        *self_p = NULL;
    }
}

dharanikumar-s avatar May 12 '16 05:05 dharanikumar-s

Hi, dharanikumarsrvnrntbci, short answer yes!

mlm_client_destructor calls s_accept_reply as do any reply accepting messages. s_accept_reply itself will immediately return with -1 if zsys_interrupted is set because s_accept_reply may take an infinite amount of time to complete. We use zsys_interrupted to terminate gracefully and waiting an unknown amount of time for an answer isn't graceful at least from the client's perspective.

sappo avatar May 12 '16 07:05 sappo

Hi sappo, I can understand s_accept_reply is used for many function, and it should be terminated when interrupted in those scenarios. But leaving s_accept_reply usage aside, when client being destructed, it needs to inform the server about disconnecting. isn't it? Just curious to know.

dharanikumar-s avatar May 12 '16 12:05 dharanikumar-s