From 1e1ce9eda7613c14fe7510bcde9c67160ef2d263 Mon Sep 17 00:00:00 2001 From: jikstra Date: Tue, 16 Jul 2019 01:12:40 +0200 Subject: [PATCH 1/4] Expose dcn_perform_imap_jobs --- src/module.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/module.c b/src/module.c index bd8aaf15..78ea6c89 100644 --- a/src/module.c +++ b/src/module.c @@ -2581,12 +2581,23 @@ NAPI_METHOD(dcn_array_get_chat_id) { return napi_chat_id; } +NAPI_METHOD(dcn_perform_imap_jobs) { + NAPI_ARGV(1); + NAPI_DCN_CONTEXT(); + + dc_perform_imap_jobs(dcn_context->dc_context); + + //TRACE("calling.."); + NAPI_RETURN_UNDEFINED(); +} + NAPI_INIT() { /** * Main context */ NAPI_EXPORT_FUNCTION(dcn_context_new); + NAPI_EXPORT_FUNCTION(dcn_perform_imap_jobs); /** * Static functions From 83f5946203e68c1ebe28769415037e5d4b6816b2 Mon Sep 17 00:00:00 2001 From: jikstra Date: Tue, 16 Jul 2019 02:45:45 +0200 Subject: [PATCH 2/4] Never block when trying to call back into js, otherwise we easily produce a deadlock. Increase max queue size to 1000 (100 is too small when importing a backup). --- src/module.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/module.c b/src/module.c index 78ea6c89..0f33ec01 100644 --- a/src/module.c +++ b/src/module.c @@ -82,7 +82,13 @@ static uintptr_t dc_event_handler(dc_context_t* dc_context, int event, uintptr_t dcn_event->data1_str = (DC_EVENT_DATA1_IS_STRING(event) && data1) ? strdup((char*)data1) : NULL; dcn_event->data2_str = (DC_EVENT_DATA2_IS_STRING(event) && data2) ? strdup((char*)data2) : NULL; - napi_call_threadsafe_function(dcn_context->threadsafe_event_handler, dcn_event, napi_tsfn_blocking); + napi_status status = napi_call_threadsafe_function(dcn_context->threadsafe_event_handler, dcn_event, napi_tsfn_nonblocking); + + if (status == napi_queue_full) { + TRACE("Queue is full!"); + } else { + NAPI_STATUS_THROWS(status); + } return 0; } @@ -1523,7 +1529,7 @@ NAPI_METHOD(dcn_set_event_handler) { callback, 0, async_resource_name, - 100, + 1000, 1, NULL, NULL, From 34fcb40448a524eb4f87eebca8080a83c7bcbeda Mon Sep 17 00:00:00 2001 From: jikstra Date: Tue, 16 Jul 2019 02:49:10 +0200 Subject: [PATCH 3/4] Set max queue size to unlimited --- src/module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/module.c b/src/module.c index 0f33ec01..4ce85a3d 100644 --- a/src/module.c +++ b/src/module.c @@ -1529,7 +1529,7 @@ NAPI_METHOD(dcn_set_event_handler) { callback, 0, async_resource_name, - 1000, + 0, 1, NULL, NULL, From 79ee6b80b182ee2e8f371ba117e1a72ad8ccca21 Mon Sep 17 00:00:00 2001 From: jikstra Date: Tue, 16 Jul 2019 02:59:42 +0200 Subject: [PATCH 4/4] no env in that method --- src/module.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/module.c b/src/module.c index 4ce85a3d..314fab37 100644 --- a/src/module.c +++ b/src/module.c @@ -85,11 +85,9 @@ static uintptr_t dc_event_handler(dc_context_t* dc_context, int event, uintptr_t napi_status status = napi_call_threadsafe_function(dcn_context->threadsafe_event_handler, dcn_event, napi_tsfn_nonblocking); if (status == napi_queue_full) { - TRACE("Queue is full!"); - } else { - NAPI_STATUS_THROWS(status); + TRACE("Queue is full, can't call callback"); } - + return 0; }