Skip to content
This repository was archived by the owner on Jun 30, 2021. It is now read-only.
This repository was archived by the owner on Jun 30, 2021. It is now read-only.

Confusion with on_conn_error and on_error hooks #93

@damonearp

Description

@damonearp

Details

evhtp_hook_on_conn_error is never used. A quick search of the repo only shows this hook being set here evhtp.c:4325
evhtp_hook_on_error isn't used if only set in struct evhtp_connection_s. It must be explicitly set on every request struct. evhtp.c:758

Partial Workaround

Use evhtp_hook_on_path to set it on the evhtp_request_t with evhtp_request_set_hook(). However on_error will only be called if the connection get's to this callback. For Example

perl -e '$|=1; print "GET /file00 HTTP/1.1\r\n"; while(<>){}' | nc localhost 8080
$ ./server 8080
error_cb

Steps or code to reproduce the problem.

  1. Set a short timeout, I used 1 second
  2. Set hooks on_conn_error and on_error
  3. connect to server with empty or partial request: ex nc localhost 8080
  4. Wait for timeout to close connection and you won't see logging from either error callbacks.

Example code (if applicable)

evhtp_res 
conn_error_cb(evhtp_connection_t *conn, evhtp_error_flags type, void *arg)
{
    printf("%s\n", __FUNCTION__);
    return EVHTP_RES_OK;
}

evhtp_res 
error_cb(evhtp_request_t *req, evhtp_error_flags type, void *arg)
{
    printf("%s\n", __FUNCTION__);
    return EVHTP_RES_OK;
}

evhtp_res 
pre_accept_cb(evhtp_connection_t *conn, void *arg)
{
    evhtp_connection_set_hook(conn, evhtp_hook_on_conn_error, &conn_error_cb, NULL);
    evhtp_connection_set_hook(conn, evhtp_hook_on_error, &error_cb, NULL);
    return EVHTP_RES_OK;
}

int
main(int argc, const char ** argv)
{
    struct timeval = { .tv_sec = 1, .tv_usec = 0 };
    ...
    evhtp_set_timeouts(htp, &to, &to);
    evhtp_set_pre_accept_callback(htp, &pre_accept_cb, NULL);
    ...
}

Version

1.2.16

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions