aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver
diff options
context:
space:
mode:
authorMikhail Galanin <mgalanin@mimecast.com>2018-08-14 14:21:32 +0100
committerMikhail Galanin <mgalanin@mimecast.com>2018-08-14 14:21:32 +0100
commitf9d4b50321057009489dbc673b108e6433f4ae38 (patch)
tree79b850b954d0552c95cab61cd1019c8f615d77be /src/libserver
parenta9bc3d63a38ab46217303b09f8b03d0215c2f5ea (diff)
parent1af89c35663dd364c8d46523f0d71adc64f8bde4 (diff)
downloadrspamd-f9d4b50321057009489dbc673b108e6433f4ae38.tar.gz
rspamd-f9d4b50321057009489dbc673b108e6433f4ae38.zip
Merge branch 'master' into lua-coroutine-model
Diffstat (limited to 'src/libserver')
-rw-r--r--src/libserver/dns.c36
-rw-r--r--src/libserver/events.c15
-rw-r--r--src/libserver/events.h7
3 files changed, 53 insertions, 5 deletions
diff --git a/src/libserver/dns.c b/src/libserver/dns.c
index 372ac28b7..fbf37363a 100644
--- a/src/libserver/dns.c
+++ b/src/libserver/dns.c
@@ -15,6 +15,7 @@
*/
#include <contrib/librdns/rdns.h>
+#include <contrib/librdns/dns_private.h>
#include "config.h"
#include "dns.h"
#include "rspamd.h"
@@ -49,6 +50,7 @@ struct rspamd_dns_request_ud {
gpointer ud;
rspamd_mempool_t *pool;
struct rdns_request *req;
+ struct rdns_reply *reply;
};
static void
@@ -56,6 +58,21 @@ rspamd_dns_fin_cb (gpointer arg)
{
struct rspamd_dns_request_ud *reqdata = (struct rspamd_dns_request_ud *)arg;
+ if (reqdata->reply) {
+ reqdata->cb (reqdata->reply, reqdata->ud);
+ }
+ else {
+ struct rdns_reply fake_reply;
+
+ memset (&fake_reply, 0, sizeof (fake_reply));
+ fake_reply.code = RDNS_RC_TIMEOUT;
+ fake_reply.request = reqdata->req;
+ fake_reply.resolver = reqdata->req->resolver;
+ fake_reply.requested_name = reqdata->req->requested_names[0].name;
+
+ reqdata->cb (&fake_reply, reqdata->ud);
+ }
+
rdns_request_release (reqdata->req);
if (reqdata->pool == NULL) {
@@ -68,7 +85,7 @@ rspamd_dns_callback (struct rdns_reply *reply, gpointer ud)
{
struct rspamd_dns_request_ud *reqdata = ud;
- reqdata->cb (reply, reqdata->ud);
+ reqdata->reply = reply;
if (reqdata->session) {
/*
@@ -78,8 +95,12 @@ rspamd_dns_callback (struct rdns_reply *reply, gpointer ud)
rdns_request_retain (reply->request);
rspamd_session_remove_event (reqdata->session, rspamd_dns_fin_cb, reqdata);
}
- else if (reqdata->pool == NULL) {
- g_free (reqdata);
+ else {
+ reqdata->cb (reply, reqdata->ud);
+
+ if (reqdata->pool == NULL) {
+ g_free (reqdata);
+ }
}
}
@@ -101,13 +122,18 @@ make_dns_request (struct rspamd_dns_resolver *resolver,
return FALSE;
}
+ if (session && rspamd_session_is_destroying (session)) {
+ return FALSE;
+ }
+
if (pool != NULL) {
reqdata =
- rspamd_mempool_alloc (pool, sizeof (struct rspamd_dns_request_ud));
+ rspamd_mempool_alloc0 (pool, sizeof (struct rspamd_dns_request_ud));
}
else {
- reqdata = g_malloc (sizeof (struct rspamd_dns_request_ud));
+ reqdata = g_malloc0 (sizeof (struct rspamd_dns_request_ud));
}
+
reqdata->pool = pool;
reqdata->session = session;
reqdata->cb = cb;
diff --git a/src/libserver/events.c b/src/libserver/events.c
index 9b0d049d4..f62005b96 100644
--- a/src/libserver/events.c
+++ b/src/libserver/events.c
@@ -172,6 +172,13 @@ rspamd_session_add_event (struct rspamd_async_session *session,
g_assert_not_reached ();
}
+ if (RSPAMD_SESSION_IS_DESTROYING (session)) {
+ msg_debug_session ("skip adding event subsystem: %s: session is destroying",
+ g_quark_to_string (subsystem));
+
+ return NULL;
+ }
+
new_event = rspamd_mempool_alloc (session->pool,
sizeof (struct rspamd_async_event));
new_event->fin = fin;
@@ -502,4 +509,12 @@ rspamd_session_mempool (struct rspamd_async_session *session)
g_assert (session != NULL);
return session->pool;
+}
+
+gboolean
+rspamd_session_is_destroying (struct rspamd_async_session *session)
+{
+ g_assert (session != NULL);
+
+ return RSPAMD_SESSION_IS_DESTROYING (session);
} \ No newline at end of file
diff --git a/src/libserver/events.h b/src/libserver/events.h
index 760bb000c..10ccb8d1d 100644
--- a/src/libserver/events.h
+++ b/src/libserver/events.h
@@ -148,4 +148,11 @@ void rspamd_session_watcher_pop (struct rspamd_async_session *s,
struct rspamd_async_watcher* rspamd_session_get_watcher (
struct rspamd_async_session *s);
+/**
+ * Returns TRUE if an async session is currently destroying
+ * @param s
+ * @return
+ */
+gboolean rspamd_session_is_destroying (struct rspamd_async_session *s);
+
#endif /* RSPAMD_EVENTS_H */