Plutonomicon / cardano-transaction-lib

A Purescript library for building smart contract transactions on Cardano
https://plutonomicon.github.io/cardano-transaction-lib/
MIT License
93 stars 50 forks source link

Concurrent contract calls cause WS connections to break. #697

Closed adamczykm closed 2 years ago

adamczykm commented 2 years ago

If a CTL client calls multiple contracts at once, it causes existing WebSockets to break. Any subsequent calls will fail. I can provide more details and a way to replicate the bug after the next weekend. ( meanwhile @klntsky can add some conjectures )

[ERROR] 2022-07-06T23:04:20.138Z First connection to Ogmios WebSocket failed. Terminating. Error: [object Event]
output.js?ee2e:2295 Uncaught Error: [object Event]
    at Object.exports.error (output.js?ee2e:2295:1)
    at __do (output.js?ee2e:24655:1)
    at listener (output.js?ee2e:16144:1)
    at ReconnectingWebSocket._callEventListener (reconnecting-websocket-mjs.js?37ac:555:1)
    at eval (reconnecting-websocket-mjs.js?37ac:183:66)
    at Array.forEach (<anonymous>)
    at WebSocket.ReconnectingWebSocket._handleError (reconnecting-websocket-mjs.js?37ac:183:1)
    ...
klntsky commented 2 years ago

So the problem is that we don't close our websockets after execution. We need to support both websocket reuse and parallel execution, so there should be an option to not close the websockets after a runContract call, but by default we should do that.

klntsky commented 2 years ago

The quick-and-dirty solution would be to add these to runQueryM, but it will make impossible to reuse the websockets:

  liftEffect $ _wsClose $ underlyingWebSocket cfg.ogmiosWs
  liftEffect $ _wsClose $ underlyingWebSocket cfg.datumCacheWs

I'm working on QueryM reorganization.