# Debugging (potential) issue with http-json-api

**URL:** <https://forum.canton.network/t/debugging-potential-issue-with-http-json-api/3823>\
**Category:** App Development\
**Created:** [January 31, 2022, 4:13pm UTC](https://forum.canton.network/t/debugging-potential-issue-with-http-json-api/3823 "2022-01-31T16:13:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Porter](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/daniel_porter/32/1171_2.png) [@Daniel\_Porter](https://forum.canton.network/u/Daniel_Porter)\
**Post date:** [January 31, 2022, 4:13pm UTC](https://forum.canton.network/t/debugging-potential-issue-with-http-json-api/3823/1 "2022-01-31T16:13:06Z")

</div>

Hi there,

I’m working on a project where we have an architecture something like this:  
`client -> custom-http-json-api-proxy -> http-json-api -> ledger`. Under load under circumstances we’re having trouble reproducing, we’re getting an issue where calls to `/exercise` from `http-json-api-proxy` succeed on the ledger, but fail to return. The sequence of events is something like:

1. `http-json-api-proxy` forwards a `POST` request
2. stuff gets written to the ledger
3. `http-json-api` waits 2 seconds, logs that it has returned a 200 response
4. `http-json-api-proxy` waits ~30 seconds, then reports a `503` error.

This smells like some kind resource exhaustion (thread pools maybe, b/c akka), but because we can’t yet reproduce it in a non-prod environment (and for the moment the application is turned off in prod), it’s a little difficult to diagnose. Notably, we’re _also_ proxying websocket requests, which are consistently getting borked (probably by our proxy), closed, and retried, so there’s a potential mechanism for thread pool exhaustion, either on our proxy, or on `http-json-api`. Also haven’t repro’d, and probably need `tcpdump` + better visibility into what’s happening on `http-json-api` to diagnose.

So, anyways, that’s background. Got a couple of questions.

1. What facility is there to see the runtime workings of `http-json-api`?
2. How much effort would it be to build my own `http-json-api` maybe with `akka-http-metrics` baked in?
3. Any suggestions on how to diagnose this?
4. Any idle thoughts on how `http-json-api` might log a success without actually returning it?

---

<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:** [February 1, 2022, 10:04am UTC](https://forum.canton.network/t/debugging-potential-issue-with-http-json-api/3823/2 "2022-02-01T10:04:27Z")

</div>

> [@Daniel\_Porter](#):
>
> What facility is there to see the runtime workings of `http-json-api` ?

I’m not 100% sure of what exactly you would like to see here, but we do have a set of metrics and logging that is available, which is described more in depth on the [documentation](https://docs.daml.com/1.18.1/json-api/production-setup.html).

> [@Daniel\_Porter](#):
>
> How much effort would it be to build my own `http-json-api` maybe with `akka-http-metrics` baked in?

I cannot quantify the effort, but I wouldn’t say much more than half a day. Perhaps @Stephen or @victor.pr.mueller can give you a more informed answer.

As for the two remaining questions, I would again ask either Stephen or Victor to suggest their ideas. Looking at the description of the problem it appears that it’s something happening at the proxy level (I had a quick look about this issue a few days and found a [StackOverflow answer](https://stackoverflow.com/a/68870731) that seemed to point out at the proxy being unable to support request timeouts for streams – but I’m not sure whether you’re using Envoy as a proxy and/or if this applies in your case).

---

<div class="post-metadata">

**Author:** ![Daniel\_Porter](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/daniel_porter/32/1171_2.png) [@Daniel\_Porter](https://forum.canton.network/u/Daniel_Porter)\
**Post date:** [February 1, 2022, 2:58pm UTC](https://forum.canton.network/t/debugging-potential-issue-with-http-json-api/3823/3 "2022-02-01T14:58:05Z")

</div>

> I’m not 100% sure of what exactly you would like to see here

At the moment what I’d like to see in particular is akka thread pool information sans having to do a thread dump and make sense of it.

1. are there any facilities or planned facilities for being able to increase log level without having to bounce the JVM process?
2. ditto for metrics
3. is there any plan for being able to supply a `trace-id`/correlation-id for tracing requests end-to-end through the system, a la canton?
4. is there any supplied way to get visibility into the threadpool?

I also suspect the 503 issue is being caused by the proxy, but is unclear if it’s manifesting in our proxy or in `http-json-api`. Our architecture is really more something like `cloudarmor` → `istio` → `json-api-proxy` → `http-json-api` → `ledger`, where `json-api-proxy` is a proxy we’ve written with akka. I think envoy is in the mix, but it’s not sitting between the two failing components.

---

<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:** [February 1, 2022, 4:17pm UTC](https://forum.canton.network/t/debugging-potential-issue-with-http-json-api/3823/4 "2022-02-01T16:17:58Z")

</div>

> [@Daniel\_Porter](#):
>
> are there any facilities or planned facilities for being able to increase log level without having to bounce the JVM process?

Not without bounding the process, no.

> [@Daniel\_Porter](#):
>
> ditto for metrics

All metrics are always recorded.

> [@Daniel\_Porter](#):
>
> is there any plan for being able to supply a `trace-id` /correlation-id for tracing requests end-to-end through the system, a la canton?

There is a `request_id` that is part of the context of each log entry. There is also an `instance_id` in case you are aggregating logs for multiple HTTP JSON API instances in a single collector.

> [@Daniel\_Porter](#):
>
> is there any supplied way to get visibility into the threadpool?

Not currently, no.

---

<div class="post-metadata">

**Author:** ![Daniel\_Porter](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/daniel_porter/32/1171_2.png) [@Daniel\_Porter](https://forum.canton.network/u/Daniel_Porter)\
**Post date:** [February 1, 2022, 5:50pm UTC](https://forum.canton.network/t/debugging-potential-issue-with-http-json-api/3823/5 "2022-02-01T17:50:08Z")

</div>

> [@stefanobaghino-da](#):
>
> > [@Daniel\_Porter](#):
> >
> > is there any supplied way to get visibility into the threadpool?
> 
> Not currently, no.

Are there plans in the future to expose this?

---

<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:** [February 1, 2022, 5:58pm UTC](https://forum.canton.network/t/debugging-potential-issue-with-http-json-api/3823/6 "2022-02-01T17:58:58Z")

</div>

> [@Daniel\_Porter](#):
>
> Are there plans in the future to expose this?

There are no plans currently to expose the thread pool metrics.

---

<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:** [February 1, 2022, 8:52pm UTC](https://forum.canton.network/t/debugging-potential-issue-with-http-json-api/3823/7 "2022-02-01T20:52:45Z")

</div>

> [@Daniel\_Porter](#):
>
> How much effort would it be to build my own `http-json-api` maybe with `akka-http-metrics` baked in?

It’s pretty easy to get building on the `daml` repo. Have `git` installed, [follow the instructions](https://github.com/digital-asset/daml/#1-clone-this-repository), then `bazel build //ledger-service/http-json:http-json-binary` to make yourself a standalone jar and runscript if you need one.

Some starting points are `Endpoints.scala` and `HttpService.scala` in that tree, and `bazel-java-deps.bzl` for manipulating the available libraries from Maven. I couldn’t say what the difficulty of working in `akka-http-metrics` would be, though, nor its efficacy.

> [@Daniel\_Porter](#):
>
> Any idle thoughts on how `http-json-api` might log a success without actually returning it?

At that point control should have passed out of `Endpoints` and back to akka-http, unless the log you’re talking about is _specifically_ the one that says `"Responding to client with HTTP..."`. There would be more interesting things to look at were this one of the streaming responses, but `exercise` is a strict response, so everything interesting has already happened by that log.
