# JSON API service's websocket default timeout and how to set no-timeout?

**URL:** <https://forum.canton.network/t/json-api-services-websocket-default-timeout-and-how-to-set-no-timeout/5754>\
**Category:** App Development\
**Tags:** daml, json-api\
**Created:** [December 6, 2022, 7:59am UTC](https://forum.canton.network/t/json-api-services-websocket-default-timeout-and-how-to-set-no-timeout/5754 "2022-12-06T07:59:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julius\_William](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/julius_william/32/2966_2.png) [@Julius\_William](https://forum.canton.network/u/Julius_William)\
**Post date:** [December 6, 2022, 7:59am UTC](https://forum.canton.network/t/json-api-services-websocket-default-timeout-and-how-to-set-no-timeout/5754/1 "2022-12-06T07:59:35Z")

</div>

Hi all,

I had the below questions regarding the Websocket config for the JSON API service.

May I know if

1. There is a default timeout set for the JSON API websocket?
2. Is it possible to set no timeout for the JSON API websocket?

JSON API Websocket example config section available on the docs:  
**//Optional websocket configuration parameters**  
**websocket-config {**  
**//Maximum websocket session duration**  
**max-duration = 120m**  
**//Server-side heartbeat interval duration**  
**heartbeat-period = 5s**  
**//akka stream throttle-mode one of either `shaping` or `enforcing`**  
**mode = “shaping”**  
**}**

Thank you!

---

<div class="post-metadata">

**Author:** ![stefanobaghino-da](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/stefanobaghino-da/32/7057_2.png) [@stefanobaghino-da](https://forum.canton.network/u/stefanobaghino-da)\
**Post date:** [December 6, 2022, 9:52am UTC](https://forum.canton.network/t/json-api-services-websocket-default-timeout-and-how-to-set-no-timeout/5754/2 "2022-12-06T09:52:40Z")

</div>

The default timeout is 2 hours. You cannot set WebSocket session to never expire. You can however set it to an arbitrarily large value (see [here](https://github.com/lightbend/config/blob/4458ea947a7a2a668bb811a122455f1f05975172/HOCON.md#duration-format) on how to specify a duration in HOCON), but this would mean that a growing number of possibly inactive clients would open streams to the server that might use resources and mostly go unused from a functional perspective. The recommendation is to keep it low (two hours is already very generous, possibly excessive) and handle gracefully connections being closed (which might happen anyway regardless of the configuration limit – e.g. due to a transient network error), possibly limiting the open streams to the bare essential to avoid overwhelming the server.

See [this](https://github.com/digital-asset/daml/issues/11230#issuecomment-943067940) ticket for further details.

---

<div class="post-metadata">

**Author:** ![Julius\_William](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/julius_william/32/2966_2.png) [@Julius\_William](https://forum.canton.network/u/Julius_William)\
**Post date:** [December 6, 2022, 9:53am UTC](https://forum.canton.network/t/json-api-services-websocket-default-timeout-and-how-to-set-no-timeout/5754/3 "2022-12-06T09:53:23Z")

</div>

Thank you @stefanobaghino-da !

---

<div class="post-metadata">

**Author:** ![Stephen](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/stephen/32/102_2.png) [@Stephen](https://forum.canton.network/u/Stephen)\
**Post date:** [December 6, 2022, 6:25pm UTC](https://forum.canton.network/t/json-api-services-websocket-default-timeout-and-how-to-set-no-timeout/5754/4 "2022-12-06T18:25:05Z")

</div>

To put it a little more strongly: as discussed earlier in that ticket, [setting a very long timeout cannot possibly give you the desired client behavior of a “stream that keeps working indefnitely”](https://github.com/digital-asset/daml/issues/11230#issuecomment-942408924). So if your application doesn’t work right with the duration set to 5 minutes, it will not be well-behaved anyhow.

---

<div class="post-metadata">

**Author:** ![Julius\_William](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/julius_william/32/2966_2.png) [@Julius\_William](https://forum.canton.network/u/Julius_William)\
**Post date:** [December 7, 2022, 12:36am UTC](https://forum.canton.network/t/json-api-services-websocket-default-timeout-and-how-to-set-no-timeout/5754/5 "2022-12-07T00:36:52Z")

</div>

Well noted @Stephen thank you!
