API POST v1/query results in "Endpoints.ServerError: java.sql.BatchUpdateException:

Recently I encountered an issue with the JSON API

POST v1/query

which creates this error.

{

    "result": [],

    "errors": [

        "Endpoints.ServerError: java.sql.BatchUpdateException: Batch entry 1 INSERT INTO ledger_offset VALUES('Operator', 30, '00000000000000160000000000000000') was aborted: ERROR: duplicate key value violates unique constraint \"ledger_offset_pkey\"\n  Detail: Key (party, tpid)=(Operator, 30) already exists.  Call getNextException to see other errors in the batch."

    ],

    "status": 501

}

This seems to be the case on any query, but the API GET v1/query is working fine

we are developing on SDK 1.7

and also executing the following script upon startup :

daml json-api --ledger-host localhost --ledger-port 6865  --http-port 7575 --max-inbound-message-size 4194304 --package-reload-interval 5s --static-content "prefix=static,directory=./static-content"  --access-token-file ./token/token   --query-store-jdbc-config "driver=org.postgresql.Driver,url=jdbc:postgresql://localhost:5432/loci?&ssl=false,user=xxx,password=xxxx,createSchema=true"

Hi @bartcant, is this issue reproducible?

The reason why the GET request works is that the wildcard requests don’t hit the database at all. They are more intended for debugging than as a production feature.

If possible, it would be great if you could share a sql dump with us and maybe the project.

As for fixing this issue, the JSON API only uses the database as a cache so you can reinitialize it and hopefully work around the issue that way. To do so, run it once with createSchema=true like you did the first time and then run it with createSchema=false again.

Hi @cocreature.
we are able to re-create this issue on all Post queries.
I re-started the JSON-API with createschema=true and then createschema=false

λ daml json-api --ledger-host localhost --ledger-port 6865 --http-port 7575 --max-inbound-message-size 4194304 --package-reload-interval 5s --static-content “prefix=static,directory=./static-content” --access-token-file ./token/token --query-store-jdbc-config “driver=org.postgresql.Driver,url=jdbc:postgresql://localhost:5432/loci?&ssl=false,user=Bart,password=password,createSchema=true”
08:17:59.163 [main] INFO com.daml.http.Main$ - Config(ledgerHost=localhost, ledgerPort=6865, address=127.0.0.1, httpPort=7575, portFile=None, packageReloadInterval=5 seconds, packageMaxInboundMessageSize=None, maxInboundMessageSize=4194304, tlsConfig=TlsConfiguration(false,None,None,None,REQUIRE), jdbcConfig=Some(JdbcConfig(driver=org.postgresql.Driver, url=jdbc:postgresql://localhost:5432/loci?&ssl=false, user=Bart, createSchema=true)), staticContentConfig=Some(StaticContentConfig(prefix=static, directory=C:\Users\bartc\Documents\Github\Loci.\static-content)), allowNonHttps=false, accessTokenFile=Some(.\token\token), wsConfig=None)
08:17:59.560 [http-json-ledger-api-akka.actor.default-dispatcher-5] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
08:18:02.018 [main] INFO com.daml.http.Main$ - Creating DB schema…
Nov 16, 2020 8:18:02 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

DROP TABLE IF EXISTS contract

arguments = []
elapsed = 30 ms exec + 0 ms processing (30 ms total)

Nov 16, 2020 8:18:02 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

DROP TABLE IF EXISTS ledger_offset

arguments = []
elapsed = 10 ms exec + 0 ms processing (10 ms total)

Nov 16, 2020 8:18:02 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

DROP TABLE IF EXISTS template_id

arguments = []
elapsed = 11 ms exec + 0 ms processing (11 ms total)

Nov 16, 2020 8:18:02 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

    CREATE TABLE
      template_id
      (tpid BIGSERIAL PRIMARY KEY NOT NULL
      ,package_id TEXT NOT NULL
      ,template_module_name TEXT NOT NULL
      ,template_entity_name TEXT NOT NULL
      ,UNIQUE (package_id, template_module_name, template_entity_name)
      )

arguments = []
elapsed = 32 ms exec + 0 ms processing (32 ms total)

Nov 16, 2020 8:18:02 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

    CREATE TABLE
      ledger_offset
      (party TEXT NOT NULL
      ,tpid BIGINT NOT NULL REFERENCES template_id (tpid)
      ,last_offset TEXT NOT NULL
      ,PRIMARY KEY (party, tpid)
      )

arguments = []
elapsed = 12 ms exec + 0 ms processing (12 ms total)

Nov 16, 2020 8:18:02 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

    CREATE TABLE
      contract
      (contract_id TEXT PRIMARY KEY NOT NULL
      ,tpid BIGINT NOT NULL REFERENCES template_id (tpid)
      ,key JSONB NOT NULL
      ,payload JSONB NOT NULL
      ,signatories TEXT ARRAY NOT NULL
      ,observers TEXT ARRAY NOT NULL
      ,agreement_text TEXT NOT NULL
      )

arguments = []
elapsed = 10 ms exec + 0 ms processing (10 ms total)

Nov 16, 2020 8:18:02 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

    CREATE INDEX ON contract (tpid)

arguments = []
elapsed = 4 ms exec + 0 ms processing (4 ms total)

08:18:02.486 [main] INFO com.daml.http.Main$ - DB schema created. Terminating process…

Here is the output that we can see in the log when doing the post query event

λ daml json-api --ledger-host localhost --ledger-port 6865 --http-port 7575 --max-inbound-message-size 4194304 --package-reload-interval 5s --static-content “prefix=static,directory=./static-content” --access-token-file ./token/token --query-store-jdbc-config “driver=org.postgresql.Driver,url=jdbc:postgresql://localhost:5432/loci?&ssl=false,user=Bart,password=password,createSchema=false”
08:25:18.653 [main] INFO com.daml.http.Main$ - Config(ledgerHost=localhost, ledgerPort=6865, address=127.0.0.1, httpPort=7575, portFile=None, packageReloadInterval=5 seconds, packageMaxInboundMessageSize=None, maxInboundMessageSize=4194304, tlsConfig=TlsConfiguration(false,None,None,None,REQUIRE), jdbcConfig=Some(JdbcConfig(driver=org.postgresql.Driver, url=jdbc:postgresql://localhost:5432/loci?&ssl=false, user=Bart, createSchema=false)), staticContentConfig=Some(StaticContentConfig(prefix=static, directory=C:\Users\bartc\Documents\Github\Loci.\static-content)), allowNonHttps=false, accessTokenFile=Some(.\token\token), wsConfig=None)
08:25:19.077 [http-json-ledger-api-akka.actor.default-dispatcher-4] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
08:25:21.566 [main] INFO com.daml.auth.TokenHolder - Reading token from .\token\token…
08:25:23.026 [http-json-ledger-api-akka.actor.default-dispatcher-5] INFO com.daml.http.HttpService$ - Connected to Ledger: Loci
08:25:23.028 [http-json-ledger-api-akka.actor.default-dispatcher-5] INFO com.daml.http.HttpService$ - contractDao: Some(com.daml.http.dbbackend.ContractDao@76a2ab8)
08:25:23.037 [http-json-ledger-api-akka.actor.default-dispatcher-5] INFO com.daml.auth.TokenHolder - Reading token from .\token\token…
08:25:24.017 [http-json-ledger-api-akka.actor.default-dispatcher-5] INFO com.daml.http.PackageService - new package IDs loaded: 1f6769c5726355af704dda86ed94b15f6ecfbfdfc6a52a2a6792fbc257be3902, c1f1f00558799eec139fb4f4c76f95fb52fa1837a5dd29600baa1c8ed1bdccfd, 733e38d36a2759688a4b2c4cec69d48e7b55ecc8dedc8067b815926c917a182a, bfcd37bd6b84768e86e432f5f6c33e25d9e7724a9d42e33875ff74f6348e733f, 669fa1ab500cba71652d105332af7686e7a90fb99d8ff1545a7e8815743d1381, 518032f41fd0175461b35ae0c9691e08b4aea55e62915f8360af2cc7a1f2ba6c, cc348d369011362a5190fe96dd1f0dfbc697fdfd10e382b9e9666f0da05961b7, 6839a6d3d430c569b2425e9391717b44ca324b88ba621d597778811b2d05031d, 99a2705ed38c1c26cbb8fe7acf36bbf626668e167a33335de932599219e0a235, 76bf0fd12bd945762a01f8fc5bbcdfa4d0ff20f8762af490f8f41d6237c6524f, e22bce619ae24ca3b8e6519281cb5a33b64b3190cc763248b4c3f9ad5087a92c, d58cf9939847921b2aab78eaa7b427dc4c649d25e6bee3c749ace4c3f52f5c97, 6c2c0667393c5f92f1885163068cd31800d2264eb088eb6fc740e11241b2bf06, d14e08374fc7197d6a0de468c968ae8ba3aadbf9315476fd39071831f5923662, 057eed1fd48c238491b8ea06b9b5bf85a5d4c9275dd3f6183e0e6b01730cc2ba, e491352788e56ca4603acc411ffe1a49fefd76ed8b163af86cf5ee5f4c38645b, 40f452260bef3f29dede136108fc08a88d5a5250310281067087da6f0baddff7, 5894d748a7e97b8fd49ca4dab20543066ad2fcfb4435ae2062cbc335bbb69734, ac9677ef0dcbb2cac09a2f9c90aae9896f225a20a34bb1f9248ffb8c4bec7594, 8a7806365bbd98d88b4c13832ebfa305f6abaeaf32cfa2b7dd25c4fa489b79fb
08:25:24.094 [http-json-ledger-api-akka.actor.default-dispatcher-5] WARN com.daml.http.StaticContentRouter - StaticContentRouter configured: StaticContentConfig(prefix=static, directory=C:\Users\bartc\Documents\Github\Loci.\static-content)
08:25:24.094 [http-json-ledger-api-akka.actor.default-dispatcher-5] WARN com.daml.http.StaticContentRouter - DO NOT USE StaticContentRouter IN PRODUCTION, CONSIDER SETTING UP REVERSE PROXY!!!
08:25:24.669 [http-json-ledger-api-akka.actor.default-dispatcher-5] INFO com.daml.http.Main$ - Started server: ServerBinding(/127.0.0.1:7575)
08:25:29.042 [http-json-ledger-api-akka.actor.default-dispatcher-13] INFO com.daml.auth.TokenHolder - Reading token from .\token\token…
08:25:34.077 [http-json-ledger-api-akka.actor.default-dispatcher-13] INFO com.daml.auth.TokenHolder - Reading token from .\token\token…
08:25:34.560 [http-json-ledger-api-akka.actor.default-dispatcher-6] WARN com.daml.http.Endpoints - missing HTTPS reverse-proxy request headers; for development launch with --allow-insecure-tokens
Nov 16, 2020 8:25:36 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT tpid FROM template_id
WHERE (package_id = ? AND template_module_name = ?
AND template_entity_name = ?)

arguments = [669fa1ab500cba71652d105332af7686e7a90fb99d8ff1545a7e8815743d1381, SurgicalEvent, SurgicalEvent]
elapsed = 39 ms exec + 66 ms processing (106 ms total)

Nov 16, 2020 8:25:36 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT party, last_offset FROM ledger_offset WHERE (party = ANY(?) AND tpid = ?)

arguments = [Vector(Operator, Operator), 7]
elapsed = 4 ms exec + 0 ms processing (4 ms total)

Nov 16, 2020 8:25:36 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT tpid FROM template_id
WHERE (package_id = ? AND template_module_name = ?
AND template_entity_name = ?)

arguments = [669fa1ab500cba71652d105332af7686e7a90fb99d8ff1545a7e8815743d1381, SurgicalEvent, SurgicalEvent]
elapsed = 2 ms exec + 3 ms processing (6 ms total)

Nov 16, 2020 8:25:36 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT tpid FROM template_id
WHERE (package_id = ? AND template_module_name = ?
AND template_entity_name = ?)

arguments = [669fa1ab500cba71652d105332af7686e7a90fb99d8ff1545a7e8815743d1381, SurgicalEvent, SurgicalEvent]
elapsed = 3 ms exec + 2 ms processing (6 ms total)

Nov 16, 2020 8:25:36 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT tpid FROM template_id
WHERE (package_id = ? AND template_module_name = ?
AND template_entity_name = ?)

arguments = [669fa1ab500cba71652d105332af7686e7a90fb99d8ff1545a7e8815743d1381, SurgicalEvent, SurgicalEvent]
elapsed = 1 ms exec + 1 ms processing (2 ms total)

Nov 16, 2020 8:25:36 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT party, last_offset FROM ledger_offset WHERE (party = ANY(?) AND tpid = ?)

arguments = [Vector(Operator, Operator), 8]
elapsed = 1 ms exec + 0 ms processing (2 ms total)

Nov 16, 2020 8:25:36 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT tpid FROM template_id
WHERE (package_id = ? AND template_module_name = ?
AND template_entity_name = ?)

arguments = [669fa1ab500cba71652d105332af7686e7a90fb99d8ff1545a7e8815743d1381, SurgicalEvent, SurgicalEvent]
elapsed = 1 ms exec + 1 ms processing (3 ms total)

Nov 16, 2020 8:25:36 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT tpid FROM template_id
WHERE (package_id = ? AND template_module_name = ?
AND template_entity_name = ?)

arguments = [669fa1ab500cba71652d105332af7686e7a90fb99d8ff1545a7e8815743d1381, SurgicalEvent, SurgicalEvent]
elapsed = 1 ms exec + 1 ms processing (2 ms total)

Nov 16, 2020 8:25:37 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT tpid FROM template_id
WHERE (package_id = ? AND template_module_name = ?
AND template_entity_name = ?)

arguments = [669fa1ab500cba71652d105332af7686e7a90fb99d8ff1545a7e8815743d1381, SurgicalEvent, SurgicalEvent]
elapsed = 1 ms exec + 13 ms processing (15 ms total)

Nov 16, 2020 8:25:37 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT party, last_offset FROM ledger_offset WHERE (party = ANY(?) AND tpid = ?)

arguments = [Vector(Operator, Operator), 9]
elapsed = 2 ms exec + 1 ms processing (3 ms total)

Nov 16, 2020 8:25:37 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT tpid FROM template_id
WHERE (package_id = ? AND template_module_name = ?
AND template_entity_name = ?)

arguments = [669fa1ab500cba71652d105332af7686e7a90fb99d8ff1545a7e8815743d1381, SurgicalEvent, SurgicalEvent]
elapsed = 1 ms exec + 1 ms processing (3 ms total)

Nov 16, 2020 8:25:37 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT tpid FROM template_id
WHERE (package_id = ? AND template_module_name = ?
AND template_entity_name = ?)

arguments = [669fa1ab500cba71652d105332af7686e7a90fb99d8ff1545a7e8815743d1381, SurgicalEvent, SurgicalEvent]
elapsed = 1 ms exec + 1 ms processing (2 ms total)

Nov 16, 2020 8:25:37 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT tpid FROM template_id
WHERE (package_id = ? AND template_module_name = ?
AND template_entity_name = ?)

arguments = [669fa1ab500cba71652d105332af7686e7a90fb99d8ff1545a7e8815743d1381, SurgicalEvent, SurgicalEvent]
elapsed = 1 ms exec + 0 ms processing (1 ms total)

Nov 16, 2020 8:25:37 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT party, last_offset FROM ledger_offset WHERE (party = ANY(?) AND tpid = ?)

arguments = [Vector(Operator, Operator), 10]
elapsed = 1 ms exec + 0 ms processing (2 ms total)

Nov 16, 2020 8:25:37 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT tpid FROM template_id
WHERE (package_id = ? AND template_module_name = ?
AND template_entity_name = ?)

arguments = [669fa1ab500cba71652d105332af7686e7a90fb99d8ff1545a7e8815743d1381, SurgicalEvent, SurgicalEvent]
elapsed = 1 ms exec + 0 ms processing (2 ms total)

Nov 16, 2020 8:25:37 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT tpid FROM template_id
WHERE (package_id = ? AND template_module_name = ?
AND template_entity_name = ?)

arguments = [669fa1ab500cba71652d105332af7686e7a90fb99d8ff1545a7e8815743d1381, SurgicalEvent, SurgicalEvent]
elapsed = 1 ms exec + 0 ms processing (1 ms total)

Nov 16, 2020 8:25:37 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT tpid FROM template_id
WHERE (package_id = ? AND template_module_name = ?
AND template_entity_name = ?)

arguments = [669fa1ab500cba71652d105332af7686e7a90fb99d8ff1545a7e8815743d1381, SurgicalEvent, SurgicalEvent]
elapsed = 1 ms exec + 1 ms processing (2 ms total)

Nov 16, 2020 8:25:37 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT party, last_offset FROM ledger_offset WHERE (party = ANY(?) AND tpid = ?)

arguments = [Vector(Operator, Operator), 11]
elapsed = 2 ms exec + 0 ms processing (2 ms total)

Nov 16, 2020 8:25:37 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT tpid FROM template_id
WHERE (package_id = ? AND template_module_name = ?
AND template_entity_name = ?)

arguments = [669fa1ab500cba71652d105332af7686e7a90fb99d8ff1545a7e8815743d1381, SurgicalEvent, SurgicalEvent]
elapsed = 1 ms exec + 1 ms processing (3 ms total)

Nov 16, 2020 8:25:37 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT tpid FROM template_id
WHERE (package_id = ? AND template_module_name = ?
AND template_entity_name = ?)

arguments = [669fa1ab500cba71652d105332af7686e7a90fb99d8ff1545a7e8815743d1381, SurgicalEvent, SurgicalEvent]
elapsed = 1 ms exec + 1 ms processing (2 ms total)

Nov 16, 2020 8:25:37 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT tpid FROM template_id
WHERE (package_id = ? AND template_module_name = ?
AND template_entity_name = ?)

arguments = [669fa1ab500cba71652d105332af7686e7a90fb99d8ff1545a7e8815743d1381, SurgicalEvent, SurgicalEvent]
elapsed = 1 ms exec + 1 ms processing (2 ms total)

Nov 16, 2020 8:25:37 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT party, last_offset FROM ledger_offset WHERE (party = ANY(?) AND tpid = ?)

arguments = [Vector(Operator, Operator), 12]
elapsed = 1 ms exec + 0 ms processing (2 ms total)

Nov 16, 2020 8:25:37 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT tpid FROM template_id
WHERE (package_id = ? AND template_module_name = ?
AND template_entity_name = ?)

arguments = [669fa1ab500cba71652d105332af7686e7a90fb99d8ff1545a7e8815743d1381, SurgicalEvent, SurgicalEvent]
elapsed = 1 ms exec + 1 ms processing (2 ms total)

Nov 16, 2020 8:25:37 AM doobie.util.log$LogHandler$ $anonfun$jdkLogHandler$1
INFO: Successful Statement Execution:

SELECT tpid FROM template_id
WHERE (package_id = ? AND template_module_name = ?
AND template_entity_name = ?)

arguments = [669fa1ab500cba71652d105332af7686e7a90fb99d8ff1545a7e8815743d1381, SurgicalEvent, SurgicalEvent]
elapsed = 1 ms exec + 1 ms processing (2 ms total)

08:25:37.507 [http-json-ledger-api-akka.actor.default-dispatcher-13] ERROR com.daml.http.ContractsFetch - contractsIo3 exception: java.sql.BatchUpdateException: Batch entry 1 INSERT INTO ledger_offset VALUES(‘Operator’, 12, ‘00000000000000180000000000000000’) was aborted: ERROR: duplicate key value violates unique constraint “ledger_offset_pkey”
Detail: Key (party, tpid)=(Operator, 12) already exists. Call getNextException to see other errors in the batch., state: 23505
08:25:37.524 [http-json-ledger-api-akka.actor.default-dispatcher-5] ERROR com.daml.http.Endpoints - Source failed
java.sql.BatchUpdateException: Batch entry 1 INSERT INTO ledger_offset VALUES(‘Operator’, 12, ‘00000000000000180000000000000000’) was aborted: ERROR: duplicate key value violates unique constraint “ledger_offset_pkey”
Detail: Key (party, tpid)=(Operator, 12) already exists. Call getNextException to see other errors in the batch.
at org.postgresql.jdbc.BatchResultHandler.handleError(BatchResultHandler.java:153)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2242)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:508)
at org.postgresql.jdbc.PgStatement.internalExecuteBatch(PgStatement.java:850)
at org.postgresql.jdbc.PgStatement.executeBatch(PgStatement.java:873)
at org.postgresql.jdbc.PgPreparedStatement.executeBatch(PgPreparedStatement.java:1562)
at doobie.free.KleisliInterpreter$PreparedStatementInterpreter.$anonfun$executeBatch$2(kleisliinterpreter.scala:949)
at doobie.free.KleisliInterpreter.$anonfun$primitive$2(kleisliinterpreter.scala:112)
at cats.effect.internals.IORunLoop$.cats$effect$internals$IORunLoop$$loop(IORunLoop.scala:87)
at cats.effect.internals.IORunLoop$.startCancelable(IORunLoop.scala:41)
at cats.effect.internals.IOBracket$BracketStart.run(IOBracket.scala:90)
at cats.effect.internals.Trampoline.cats$effect$internals$Trampoline$$immediateLoop(Trampoline.scala:67)
at cats.effect.internals.Trampoline.startLoop(Trampoline.scala:35)
at cats.effect.internals.TrampolineEC$JVMTrampoline.super$startLoop(TrampolineEC.scala:90)
at cats.effect.internals.TrampolineEC$JVMTrampoline.$anonfun$startLoop$1(TrampolineEC.scala:90)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:85)
at cats.effect.internals.TrampolineEC$JVMTrampoline.startLoop(TrampolineEC.scala:90)
at cats.effect.internals.Trampoline.execute(Trampoline.scala:43)
at cats.effect.internals.TrampolineEC.execute(TrampolineEC.scala:42)
at cats.effect.internals.IOBracket$BracketStart.apply(IOBracket.scala:70)
at cats.effect.internals.IOBracket$BracketStart.apply(IOBracket.scala:50)
at cats.effect.internals.IORunLoop$.cats$effect$internals$IORunLoop$$loop(IORunLoop.scala:141)
at cats.effect.internals.IORunLoop$RestartCallback.signal(IORunLoop.scala:366)
at cats.effect.internals.IORunLoop$RestartCallback.apply(IORunLoop.scala:387)
at cats.effect.internals.IORunLoop$RestartCallback.apply(IORunLoop.scala:330)
at cats.effect.internals.IOShift$Tick.run(IOShift.scala:36)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:830)
Caused by: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint “ledger_offset_pkey”
Detail: Key (party, tpid)=(Operator, 12) already exists.
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2505)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2241)
… 28 common frames omitted
08:25:39.107 [http-json-ledger-api-akka.actor.default-dispatcher-5] INFO com.daml.auth.TokenHolder - Reading token from .\token\token…
08:25:44.152 [http-json-ledger-api-akka.actor.default-dispatcher-13] INFO com.daml.auth.TokenHolder - Reading token from .\token\token…
08:25:49.207 [http-json-ledger-api-akka.actor.default-dispatcher-13] INFO com.daml.auth.TokenHolder - Reading token from .\token\token…
08:25:54.236 [http-json-ledger-api-akka.actor.default-dispatcher-13] INFO com.daml.auth.TokenHolder - Reading token from .\token\token…
08:25:59.266 [http-json-ledger-api-akka.actor.default-dispatcher-5] INFO com.daml.auth.TokenHolder - Reading token from .\token\token…
08:26:04.302 [http-json-ledger-api-akka.actor.default-dispatcher-5] INFO com.daml.auth.TokenHolder - Reading token from .\token\token…
08:26:09.336 [http-json-ledger-api-akka.actor.default-dispatcher-13] INFO com.daml.auth.TokenHolder - Reading token from .\token\token…
08:26:14.378 [http-json-ledger-api-akka.actor.default-dispatcher-13] INFO com.daml.auth.TokenHolder - Reading token from .\token\token…

We will see if we can re-create in SDK 1.6

Hi @bartcant, the issue arises if the same party is specified in both readAs and actAs due to a missing duplication step on our side. We’re working on a fix. In the meantime, you can remove the party from readAs since actAs already implies readAs anyway so specifying it in both is redundant.

Ok. After I updated my token the error was resolved

The fix has been merged and will be included in the next snapshot release.

:+1: Great