Replies: 3 comments 2 replies
-
I am facing a very similar issue. I am employing |
Beta Was this translation helpful? Give feedback.
-
Experiencing similar issues |
Beta Was this translation helpful? Give feedback.
-
I'm implementing a similar strategy like the one shared above by @nstylo. My issue now is handling a reconnection event properly, which does happen even when pinging regularly. If there was a reconnection, I want to attach again the event listeners that handle the pinging mechanism. If a reconnection happens, does Viem use the same WebSocket client? What I'm trying to understand is whether I can use the "open" event in order to reassign the listeners. |
Beta Was this translation helpful? Give feedback.
-
Hi Viem Community,
I've encountered a peculiar behavior with
PublicClient
instances created using WSS transport. It appears that after a few hours of inactivity, newly created instances immediately fail to watch contract events. This inactivity refers to not creating or using new instances during this time. The issue isn't tied to the lifetime of any single instance but seems related to the time elapsed since the last active use across all instances.Here's how I'm setting up the
PublicClient
:When attempting to use these instances after a period of inactivity, I receive errors indicating that the WebSocket connection is closed, specifically when calling
publicClient.watchContractEvent
. Here's an example error message:And Chainstack reports HTTP 499 errors.
This seems not to be related to the number of instances but rather to the duration of inactivity. My question to the community and developers:
createPublicClient
? If so, is there a method to either ensure a fresh connection for each new instance or to keep the existing connections alive?PublicClient
instance to manage these connections better?Any insights or advice on managing these WSS connections for long-running applications would be greatly appreciated.
Thank you!
Same question on SO
Beta Was this translation helpful? Give feedback.
All reactions