tdl: Napi::Error
I started 5 clients and immediately I’m seeing this error:
libc++abi.dylib: terminating with uncaught exception of type Napi::Error
Abort trap: 6
Any suggestions?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 3
- Comments: 22 (15 by maintainers)
In version 5.1.0 I added
pause()andresume()functions. You can use multiple clients, but not at the same time. Example:@denisakov You need tdl v6 (
npm install tdl@6.0.0-rc.2).tdl-tdlib-addonis mostly just a proof-of-concept, and it most likely won’t work from npm. You can copy it from the repository into your app.Also there is no big profit in using it, as it limited to libuv threadpool (better implementation could create a thread per client without using libuv threadpool). You can just create a process for each client instance (described above in the issue). Otherwise someone need to write
tdlib-client-actor<->node.jsbinding.It turned out that
shouldn't be called simultaneously from two different threadsis applicable only for a fixed client:So you can use multiple clients with node addon (addon example), but not with ffi, as it requires modification of
node-ffi(ornode-ffi-napi) library code. But there is a limitation, every td_receive call consumes a thread in libuv threadpool, you can’t use more thanUV_THREADPOOL_SIZE+1clients in parallel (by defaultUV_THREADPOOL_SIZEis 4, maximum is 128). IdeallyClientActorshould be used instead oftd_json_clientsomehow.I’ll update my code to use tdl v.5 and extract the multi process client as a reusable library.
I added a wrapper around
tdlthat forks and transfers updates/event/input requests via process messages and it all started to work reliably. 5 clients start simultaneously without problems. I can’t share it as I built it application specific rather than reusable (shame on me) but it was pretty straightforward.@Bannerets Honestly I believe that it should go into the library itself (or, the ff-napi should be replaced with something else), or at the very least it should be documented in README that you will need to fork in order to maintain several telegram connections.
I am having this too. If I start 3 clients at once it always crashes. If I start them one after another it works but then eventually it will crash anyway (the more clients the faster it fails).
ffi-napi documentation says: “It is recommended to avoid any multi-threading usage of this library if possible.” so chances are it’s not really possible to avoid other than going multi-process.