I stumbled upon a related issue that addresses a broader scope of this problem. The challenge isn't isolated to websocket subscriptions for events, but actually pertains to the entire websocket communication process with web3 providers.
In essence, this affects all websocket provider interactions when using Ethers.js. The core of the problem seems to be a lack of an efficient reconnection mechanism in ethers.js. As a result, the connection might get interrupted or even miss certain events, especially during reconnection attempts.
Two potential solutions stood out from the discussions on the issue:
Manual Reconnection Enhancement: Enhance the existing WebSocket behavior by introducing a custom reconnection mechanism. A sample implementation is available here.
Using the Alchemy SDK: Alternatively, you can consider the Alchemy SDK. This SDK enhances the ethers.js WebSocket provider by integrating heartbeat checks. These checks ensure the WebSocket reconnects if the connection gets dropped. Moreover, it incorporates a backfill logic, ensuring that events missed during reconnections are still emitted. However, a potential limitation is the dependency on Alchemy provider services.
Additionally, I found a discussion about a similar problem when using Infura provider with web3. It can be helpful as well.