-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Napi::Error #18
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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. |
I added a wrapper around @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. |
@IlyaSemenov I think creating process for each client is bad idea.
If you create 19000 processes, you'll get a big overhead. Also, maybe using node addon instead of ffi solves this problem. |
Sure thing it is; what I was trying to say is that it's still much better than crashing. I just thought perhaps it will be enough to add a global lock on |
I noticed that this crash happens in different cases for reasons not always clear. One reproducible example is when I send a message consisting only of spaces or tabs. I use this code: exports.sendMessage = function sendMessage(tdlClient, text) {
tdlClient.invoke({
_: 'sendMessage',
chat_id: config.telegram.chatId,
input_message_content: {
_: 'inputMessageText',
text: {
_: 'formattedText',
text,
}
}
})
}
|
@ip if you use only one client, you shouldn't get a crash (I received |
@IlyaSemenov I tested with
Sometimes I just get random bytes instead of response from tdlib. After several tries tdlib database just broke and I can't use it anymore |
@Bannerets I see you published 5.0 and some of commits in history refer to ffi. Have there been attempts to fix the multi threading issue? Is it worth upgrading / getting rid of forking per connected client? |
@IlyaSemenov This issue has not been fixed. And I think it's not possible with node-ffi. |
@IlyaSemenov can you provide an example with 1 process per client? |
I'll update my code to use tdl v.5 and extract the multi process client as a reusable library. |
In version 5.1.0 I added const client1 = new Client(...)
const client2 = new Client(...)
;(async () => {
await client1.connect()
await client1.login(...)
console.log('Client 1', await client1.invoke({ _: 'getMe' }))
client1.pause()
await client2.connect()
await client2.login(...)
console.log('Client 2', await client2.invoke({ _: 'getMe' }))
client2.pause()
client1.resume()
console.log('Client 1 again', await client1.invoke({ _: 'getMe' }))
})() |
How feasible is it to poll updates from all clients in 1-second intervals for each? Would I get flood-waited by Telegram for connecting too much? Would this slow down the rate at which I can perform actions with each account? Edit: The current situation certainly doesn't allow for an Electron multi-account client with concurrent notification polling. |
You can do something like this, but it looks like ugly hack. const client1 = new Client(...)
const client2 = new Client(...)
client1.on('update', u => console.log('From client #1', u))
client2.on('update', u => console.log('From client #2', u))
;(async () => {
await client1.connect()
await client1.login()
client1.pause()
await client2.connect()
await client2.login()
let cl1 = false
setInterval(() => {
if (cl1) { client1.pause(); client2.resume() }
else { client2.pause(); client1.resume() }
cl1 = !cl1
}, 1000)
})() |
@IlyaSemenov so are there any examples of multiprocess? |
@mnb3000 @IlyaSemenov I just published a package to make this library multiprocess. You can use it right away without any extra coding. The library is a wrapper for tdl with identical interface. It is meant as a drop-in replacement for tdl in your code. However, you must provide tdl in your own package.json to meet peer dependency. |
Just tested with node addons instead of ffi and faced with the same errors that I described in #18 (comment).
You can use some kind of mutexes, as in #18 (comment). upd: Also this may be solved using more low-level ClientActor API instead of td_json_client. |
It turned out that
So you can use multiple clients with node addon (addon example), but not with ffi, as it requires modification of |
@Bannerets, great stuff! Thank you for all the efforts.
if I try to run the node, I get: a bit lost here, I am:) Ah and the error is actually the same as the original. |
@denisakov You need tdl v6 ( 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). |
I started 5 clients and immediately I'm seeing this error:
Any suggestions?
The text was updated successfully, but these errors were encountered: