fix(ekuiper): check received aio data race

This commit is contained in:
eeff
2024-03-25 16:22:28 +08:00
parent e1429d95c8
commit 45b3aeda9a
3 changed files with 13 additions and 0 deletions
+9
View File
@@ -142,7 +142,16 @@ static inline int start(neu_plugin_t *plugin, const char *url)
return rv;
}
nng_mtx_lock(plugin->mtx);
while (plugin->receiving) {
nng_mtx_unlock(plugin->mtx);
nng_msleep(10);
nng_mtx_lock(plugin->mtx);
}
plugin->receiving = true;
nng_recv_aio(plugin->sock, plugin->recv_aio);
nng_mtx_unlock(plugin->mtx);
return NEU_ERR_SUCCESS;
}
+1
View File
@@ -37,6 +37,7 @@ struct neu_plugin {
nng_socket sock;
nng_mtx * mtx;
bool started;
bool receiving;
nng_aio * recv_aio;
char * host;
uint16_t port;
+3
View File
@@ -86,6 +86,9 @@ void recv_data_callback(void *arg)
rv = nng_aio_result(plugin->recv_aio);
if (0 != rv) {
plog_error(plugin, "nng_recv error: %s", nng_strerror(rv));
nng_mtx_lock(plugin->mtx);
plugin->receiving = false;
nng_mtx_unlock(plugin->mtx);
return;
}