[Rspamd-Users] errno as HTTP Error code

Vsevolod Stakhov vsevolod at rspamd.com
Mon Mar 8 20:42:46 UTC 2021


On 08/03/2021 19:53, Vsevolod Stakhov wrote:
> On 08/03/2021 19:47, Steve Sturges (ststurge) via Users wrote:
>> Hi all-
>>
>> Looking at rspamd 2.7 and I was trying to track down a recent issue where I got an unexpected HTTP error code back from rspamd's HTTP API when redis was having issues. Trying to trace this back from the messages in rspamd.log, I have a question about the use of errno in this code:
>>
>> static void
>> rspamd_http_event_handler (int fd, short what, gpointer ud)
>> {
>> ...
>>         else if (r == 0) {
>>             /* We can still call http parser */
>>             http_parser_execute (&priv->parser, &priv->parser_cb, d, r);
>>
>>             if (!conn->finished) {
>>                 err = g_error_new (HTTP_ERROR,
>>                         errno,
>>                         "IO read error: unexpected EOF");
>>                 conn->error_handler (conn, err);
>>                 g_error_free (err);
>>             }
>>             REF_RELEASE (pbuf);
>>             rspamd_http_connection_unref (conn);
>>
>>             return;
>>         }
>>         else {
>>             if (!priv->ssl) {
>>                 err = g_error_new (HTTP_ERROR,
>>                         errno,
>>                         "IO read error: %s",
>>                         strerror (errno));
>>                 conn->error_handler (conn, err);
>>                 g_error_free (err);
>>             }
>>
>>             REF_RELEASE (pbuf);
>>             rspamd_http_connection_unref (conn);
>>
>>             return;
>>         }
>>     }
>> ...
>>
>>
>> In other areas of this function, g_error_new is invoked with a specific HTTP error code — for example, 413, 400, 500 (500 + internal parser errno).  In the case above, where it is using errno directly that then becomes the actual HTTP code in the HTTP response generated in rspamd_http_router_error_handler().  There are other cases as well, farther down in the function above that use ETIMEDOUT directly.
>>
>> Should those errno values should be mapped to HTTP response codes, probably 503 or perhaps 408 or 504?
>>
>> Cheers
>> -steve
>>
> 
> Yes, that should be fixed, thanks.
> 

I have fixed this and various other inconsistencies I have found in this
changeset:
https://github.com/rspamd/rspamd/commit/b1e10ef14ebb91fa2ca1b61494e25fa099e85429


More information about the Users mailing list