question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] The HTTP JSON API fetches from the ledger twice

See original GitHub issue

I confirm that, if this is a bug that has security implications, I already contacted security@digitalasset.com and followed the responsible disclosure policy.

I confirm that this is not a question or a request for technical support by the community, for which the Daml forum is available.

Affected Daml version

1.18.2

Bug description

The following (redacted) piece of log shows that the same active contracts service request is issued twice to serve a single query:

28-01-2022 11:38:06.199 [http-json-ledger-api-akka.actor.default-dispatcher-5] WARN  com.daml.http.Endpoints - missing HTTPS reverse-proxy request headers; for development launch with --allow-insecure-tokens, context: {instance_uuid: "a70f6239-76a6-4275-878d-7153e2709790", request_id: "6517b9c9-63c1-4c89-96dc-a0c5f4a1ef3b"}
28-01-2022 11:38:06.461 [http-json-ledger-api-akka.actor.default-dispatcher-5] DEBUG com.daml.http.Endpoints - Processing a query request, context: {ledger_id: "some-ledger", cmd: "GetActiveContractsRequest(OneAnd(TemplateId(Some(2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949),Main,SomeTemplate),Set()),Map(),None)", request_id: "6517b9c9-63c1-4c89-96dc-a0c5f4a1ef3b", instance_uuid: "a70f6239-76a6-4275-878d-7153e2709790", application_id: "foobar", read_as: "List()", act_as: "List(Bob)"}
28-01-2022 11:38:07.338 [http-json-ledger-api-akka.actor.default-dispatcher-5] DEBUG com.daml.http.ContractsService - Searching in memory, parties: Set(Bob), templateIds: Set(TemplateId(2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949,Main,SomeTemplate)), queryParms: Params(Map()), context: {ledger_id: "some-ledger", cmd: "GetActiveContractsRequest(OneAnd(TemplateId(Some(2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949),Main,SomeTemplate),Set()),Map(),None)", request_id: "6517b9c9-63c1-4c89-96dc-a0c5f4a1ef3b", instance_uuid: "a70f6239-76a6-4275-878d-7153e2709790", application_id: "foobar", read_as: "List()", act_as: "List(Bob)"}
28-01-2022 11:38:07.484 [http-json-ledger-api-akka.actor.default-dispatcher-5] TRACE c.d.g.a.c.r.BufferingResponseObserver - Call 1: RS downstream subscription registered.
28-01-2022 11:38:07.485 [http-json-ledger-api-akka.actor.default-dispatcher-5] TRACE c.d.g.a.c.r.BufferingResponseObserver - Call 1: Starting call.
28-01-2022 11:38:07.508 [http-json-ledger-api-akka.actor.default-dispatcher-5] TRACE c.d.g.a.c.rs.BufferingSubscription - Call 1: RS downstream signaled demand for 16 elements.
28-01-2022 11:38:07.509 [http-json-ledger-api-akka.actor.default-dispatcher-4] TRACE c.d.g.a.c.rs.DownstreamEventBuffer - Call 1: Demand of 15 buffered. Total buffered is 15.
28-01-2022 11:38:07.547 [grpc-default-executor-2] TRACE c.d.g.a.c.r.BufferingResponseObserver - Call 1: gRPC upstream emitted response message GetActiveContractsResponse(,,Vector(CreatedEvent(#0000000000000006:0,0075745ddf62a316f9b6f0b3d38f42a5ef135b71ad31aa2a95e4574c6eaf13c013,Some(Identifier(2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949,Main,SomeTemplate)),None,Some(Record(Some(Identifier(2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949,Main,SomeTemplate)),Vector(RecordField(operator,Some(Value(Party(Bob)))), RecordField(someField,Some(Value(Text(123))))))),Vector(Bob),Vector(Bob),Vector(),Some()))).
28-01-2022 11:38:07.547 [http-json-ledger-api-akka.actor.default-dispatcher-4] TRACE c.d.g.a.c.rs.DownstreamEventBuffer - Call 1: Flushing demand for 15 elements. Remaining demand in buffer: 0
28-01-2022 11:38:07.548 [grpc-default-executor-2] TRACE c.d.g.a.c.r.BufferingResponseObserver - Call 1: gRPC upstream emitted response message GetActiveContractsResponse(,,Vector(CreatedEvent(#0000000000000007:0,00f08500c61bec7770f01afa6bda0f708c330a9e9da52a18c7e7ff370ab435d5ca,Some(Identifier(2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949,Main,SomeTemplate)),None,Some(Record(Some(Identifier(2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949,Main,SomeTemplate)),Vector(RecordField(operator,Some(Value(Party(Bob)))), RecordField(someField,Some(Value(Text(548))))))),Vector(Bob),Vector(Bob),Vector(),Some()))).
28-01-2022 11:38:07.548 [grpc-default-executor-2] TRACE c.d.g.a.c.r.BufferingResponseObserver - Call 1: gRPC upstream emitted response message GetActiveContractsResponse(,,Vector(CreatedEvent(#0000000000000008:0,00f10ba00db1a1dc971c115765ad15988ac1e33fccb9f98dacb1f075e537483d01,Some(Identifier(2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949,Main,SomeTemplate)),None,Some(Record(Some(Identifier(2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949,Main,SomeTemplate)),Vector(RecordField(operator,Some(Value(Party(Bob)))), RecordField(someField,Some(Value(Text(999))))))),Vector(Bob),Vector(Bob),Vector(),Some()))).
28-01-2022 11:38:07.548 [grpc-default-executor-2] TRACE c.d.g.a.c.r.BufferingResponseObserver - Call 1: gRPC upstream emitted response message GetActiveContractsResponse(,,Vector(CreatedEvent(#0000000000000009:0,007e095a02a59442b920b0fff86bea61e1e97e8bd90c3cf1e65bf017a658a22fd3,Some(Identifier(2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949,Main,SomeTemplate)),None,Some(Record(Some(Identifier(2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949,Main,SomeTemplate)),Vector(RecordField(operator,Some(Value(Party(Bob)))), RecordField(someField,Some(Value(Text(147))))))),Vector(Bob),Vector(Bob),Vector(),Some()))).
28-01-2022 11:38:07.549 [grpc-default-executor-2] TRACE c.d.g.a.c.r.BufferingResponseObserver - Call 1: gRPC upstream emitted response message GetActiveContractsResponse(0000000000009745,,Vector()).
28-01-2022 11:38:07.549 [grpc-default-executor-2] TRACE c.d.g.a.c.r.BufferingResponseObserver - Call 1: gRPC upstream completed.
28-01-2022 11:38:07.583 [http-json-ledger-api-akka.actor.default-dispatcher-5] TRACE c.d.g.a.c.r.BufferingResponseObserver - Call 2: RS downstream subscription registered.
28-01-2022 11:38:07.584 [http-json-ledger-api-akka.actor.default-dispatcher-5] TRACE c.d.g.a.c.r.BufferingResponseObserver - Call 2: Starting call.
28-01-2022 11:38:07.586 [http-json-ledger-api-akka.actor.default-dispatcher-5] TRACE c.d.g.a.c.rs.BufferingSubscription - Call 2: RS downstream signaled demand for 16 elements.
28-01-2022 11:38:07.586 [http-json-ledger-api-akka.actor.default-dispatcher-5] TRACE c.d.g.a.c.rs.DownstreamEventBuffer - Call 2: Demand of 15 buffered. Total buffered is 15.
28-01-2022 11:38:07.593 [grpc-default-executor-2] TRACE c.d.g.a.c.r.BufferingResponseObserver - Call 2: gRPC upstream completed.
28-01-2022 11:38:07.607 [http-json-ledger-api-akka.actor.default-dispatcher-5] DEBUG com.daml.http.ContractsService - contracts fetch completed at: AbsoluteBookmark(0000000000009745), context: {ledger_id: "some-ledger", cmd: "GetActiveContractsRequest(OneAnd(TemplateId(Some(2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949),Main,SomeTemplate),Set()),Map(),None)", request_id: "6517b9c9-63c1-4c89-96dc-a0c5f4a1ef3b", instance_uuid: "a70f6239-76a6-4275-878d-7153e2709790", application_id: "foobar", read_as: "List()", act_as: "List(Bob)"}
28-01-2022 11:38:07.611 [http-json-ledger-api-akka.actor.default-dispatcher-5] INFO  com.daml.http.Endpoints - Responding to client with HTTP 200 OK, context: {instance_uuid: "a70f6239-76a6-4275-878d-7153e2709790", request_id: "6517b9c9-63c1-4c89-96dc-a0c5f4a1ef3b", response_body: {result: [{agreementText: "", contractId: "0075745ddf62a316f9b6f0b3d38f42a5ef135b71ad31aa2a95e4574c6eaf13c013", observers: [], payload: {someField: "123", operator: "Bob"}, signatories: ["Bob"], templateId: "2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949:Main:SomeTemplate"}, {agreementText: "", contractId: "00f08500c61bec7770f01afa6bda0f708c330a9e9da52a18c7e7ff370ab435d5ca", observers: [], payload: {someField: "548", operator: "Bob"}, signatories: ["Bob"], templateId: "2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949:Main:SomeTemplate"}, {agreementText: "", contractId: "00f10ba00db1a1dc971c115765ad15988ac1e33fccb9f98dacb1f075e537483d01", observers: [], payload: {someField: "999", operator: "Bob"}, signatories: ["Bob"], templateId: "2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949:Main:SomeTemplate"}, {agreementText: "", contractId: "007e095a02a59442b920b0fff86bea61e1e97e8bd90c3cf1e65bf017a658a22fd3", observers: [], payload: {someField: "147", operator: "Bob"}, signatories: ["Bob"], templateId: "2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949:Main:SomeTemplate"}], status: 200}}
28-01-2022 11:38:07.614 [http-json-ledger-api-akka.actor.default-dispatcher-5] TRACE com.daml.http.Endpoints - Processed request after 1431108137ns, context: {instance_uuid: "a70f6239-76a6-4275-878d-7153e2709790", request_id: "6517b9c9-63c1-4c89-96dc-a0c5f4a1ef3b"}
28-01-2022 11:38:07.628 [http-json-ledger-api-akka.actor.default-dispatcher-9] TRACE c.d.g.a.c.r.BufferingResponseObserver - Call 3: RS downstream subscription registered.
28-01-2022 11:38:07.628 [http-json-ledger-api-akka.actor.default-dispatcher-9] TRACE c.d.g.a.c.r.BufferingResponseObserver - Call 3: Starting call.
28-01-2022 11:38:07.629 [http-json-ledger-api-akka.actor.default-dispatcher-9] TRACE c.d.g.a.c.rs.BufferingSubscription - Call 3: RS downstream signaled demand for 16 elements.
28-01-2022 11:38:07.629 [http-json-ledger-api-akka.actor.default-dispatcher-5] TRACE c.d.g.a.c.rs.DownstreamEventBuffer - Call 3: Demand of 15 buffered. Total buffered is 15.
28-01-2022 11:38:07.659 [grpc-default-executor-2] TRACE c.d.g.a.c.r.BufferingResponseObserver - Call 3: gRPC upstream emitted response message GetActiveContractsResponse(,,Vector(CreatedEvent(#0000000000000006:0,0075745ddf62a316f9b6f0b3d38f42a5ef135b71ad31aa2a95e4574c6eaf13c013,Some(Identifier(2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949,Main,SomeTemplate)),None,Some(Record(Some(Identifier(2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949,Main,SomeTemplate)),Vector(RecordField(operator,Some(Value(Party(Bob)))), RecordField(someField,Some(Value(Text(123))))))),Vector(Bob),Vector(Bob),Vector(),Some()))).
28-01-2022 11:38:07.660 [http-json-ledger-api-akka.actor.default-dispatcher-5] TRACE c.d.g.a.c.rs.DownstreamEventBuffer - Call 3: Flushing demand for 15 elements. Remaining demand in buffer: 0
28-01-2022 11:38:07.661 [grpc-default-executor-2] TRACE c.d.g.a.c.r.BufferingResponseObserver - Call 3: gRPC upstream emitted response message GetActiveContractsResponse(,,Vector(CreatedEvent(#0000000000000007:0,00f08500c61bec7770f01afa6bda0f708c330a9e9da52a18c7e7ff370ab435d5ca,Some(Identifier(2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949,Main,SomeTemplate)),None,Some(Record(Some(Identifier(2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949,Main,SomeTemplate)),Vector(RecordField(operator,Some(Value(Party(Bob)))), RecordField(someField,Some(Value(Text(548))))))),Vector(Bob),Vector(Bob),Vector(),Some()))).
28-01-2022 11:38:07.661 [grpc-default-executor-2] TRACE c.d.g.a.c.r.BufferingResponseObserver - Call 3: gRPC upstream emitted response message GetActiveContractsResponse(,,Vector(CreatedEvent(#0000000000000008:0,00f10ba00db1a1dc971c115765ad15988ac1e33fccb9f98dacb1f075e537483d01,Some(Identifier(2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949,Main,SomeTemplate)),None,Some(Record(Some(Identifier(2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949,Main,SomeTemplate)),Vector(RecordField(operator,Some(Value(Party(Bob)))), RecordField(someField,Some(Value(Text(999))))))),Vector(Bob),Vector(Bob),Vector(),Some()))).
28-01-2022 11:38:07.662 [grpc-default-executor-2] TRACE c.d.g.a.c.r.BufferingResponseObserver - Call 3: gRPC upstream emitted response message GetActiveContractsResponse(,,Vector(CreatedEvent(#0000000000000009:0,007e095a02a59442b920b0fff86bea61e1e97e8bd90c3cf1e65bf017a658a22fd3,Some(Identifier(2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949,Main,SomeTemplate)),None,Some(Record(Some(Identifier(2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949,Main,SomeTemplate)),Vector(RecordField(operator,Some(Value(Party(Bob)))), RecordField(someField,Some(Value(Text(147))))))),Vector(Bob),Vector(Bob),Vector(),Some()))).
28-01-2022 11:38:07.662 [grpc-default-executor-2] TRACE c.d.g.a.c.r.BufferingResponseObserver - Call 3: gRPC upstream emitted response message GetActiveContractsResponse(0000000000009745,,Vector()).
28-01-2022 11:38:07.662 [grpc-default-executor-2] TRACE c.d.g.a.c.r.BufferingResponseObserver - Call 3: gRPC upstream completed.
28-01-2022 11:38:07.664 [http-json-ledger-api-akka.actor.default-dispatcher-9] TRACE c.d.g.a.c.r.BufferingResponseObserver - Call 4: RS downstream subscription registered.
28-01-2022 11:38:07.664 [http-json-ledger-api-akka.actor.default-dispatcher-9] TRACE c.d.g.a.c.r.BufferingResponseObserver - Call 4: Starting call.
28-01-2022 11:38:07.665 [http-json-ledger-api-akka.actor.default-dispatcher-9] TRACE c.d.g.a.c.rs.BufferingSubscription - Call 4: RS downstream signaled demand for 16 elements.
28-01-2022 11:38:07.665 [http-json-ledger-api-akka.actor.default-dispatcher-5] TRACE c.d.g.a.c.rs.DownstreamEventBuffer - Call 4: Demand of 15 buffered. Total buffered is 15.
28-01-2022 11:38:07.672 [grpc-default-executor-2] TRACE c.d.g.a.c.r.BufferingResponseObserver - Call 4: gRPC upstream completed.
28-01-2022 11:38:07.674 [http-json-ledger-api-akka.actor.default-dispatcher-5] DEBUG com.daml.http.ContractsService - contracts fetch completed at: AbsoluteBookmark(0000000000009745), context: {ledger_id: "some-ledger", cmd: "GetActiveContractsRequest(OneAnd(TemplateId(Some(2c0a02b11c351a04e4b6735ac3cb4a8fe6bb99c82930b2ca360f715445b9b949),Main,SomeTemplate),Set()),Map(),None)", request_id: "6517b9c9-63c1-4c89-96dc-a0c5f4a1ef3b", instance_uuid: "a70f6239-76a6-4275-878d-7153e2709790", application_id: "foobar", read_as: "List()", act_as: "List(Bob)"}

To reproduce

  1. set up the HTTP JSON API to log at TRACE level
  2. start the HTTP JSON API
  3. shoot a query at POST /v1/query asking for a specific template
  4. examine your logs

Expected behavior

For each downstream query, the HTTP JSON API performs exactly one active contracts request followed by at most one flat transaction request.

Additional context

  • in this case in particular, the in-memory store was used.
  • due to the relevance of the issue, the eventual solution should probably be backported

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
gerolf-dacommented, Feb 1, 2022

It’s really about httpMessage.entity.toStrinct(...), because it materializes the response source again, outside of the regular akka-http response handling.

0reactions
realvictorprmcommented, Feb 1, 2022

I think I got a fix for this in https://github.com/digital-asset/daml/pull/12699, however I still need to do some further cleanup in there because right now it is a mess to me 😂

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solve a synchronization error - Ledger Support
A synchronization error may occur in Ledger Live when there is or has been a temporary problem with Ledger's blockchain explorers or network ......
Read more >
when am running json api in Daml am getting this error?
1 Answer 1 ... This is usually due to too large messages being sent. You can try the --max-inbound-message-size=... parameter to specify a...
Read more >
bug: Home fetch run twice · Issue #983 · kriasoft/react-starter-kit
Same here, all fetches are ran twice. It seems there is no way in which the state is saved in the HTML so...
Read more >
JSON-API Errors while doing large file processing - Daml Forum
Let me start with the second error: gRPC imposes a max size on incoming messages (but not outgoing messages). This goes in both...
Read more >
API Response & Error Codes - Mambu support
For example, the API operation has only been defined for HTTP GET request and an ... Some cases that can cause this error:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found