Are parameters to N1QL thread safe?

We have seen a weird issue intermittently, where the parameter passed to N1QL though java sdk is getting changed.
We have logs printed before executing the N1ql query and we are also logging the N1QL query that got executed.
PFB logs for the same, the parameter expected to go though(8764f27c-8295-433e-85b5-50df750fcfdb) and the parameter that went to n1ql(eb991882-59f8-40e7-91d0-5b4a9d051c5b) is highlighted in both the logs and are different.

020-09-09 11:28:24.826 INFO xxx-yyy-zzz:devperf [Trace_Perf_PA_Approve_PCI_Tpnb__20200909-11:28:23.742__f1995deb-2977-4c70-bc7d-e20ce6197305,98a76b154455b8cf,9a75b0ca1a4dac94] 23 — [cb-computations-3] a.p.d.h.xxxxx : MSG=‘Get all PriceChanges’, priceIntentId=8764f27c-8295-433e-85b5-50df750fcfdb

2020-09-09 11:28:24.826 DEBUG xxx-yyy-zzz:devperf [Trace_Perf_PA_Approve_PCI_Tpnb__20200909-11:28:23.742__f1995deb-2977-4c70-bc7d-e20ce6197305,98a76b154455b8cf,9a75b0ca1a4dac94] 23 — [cb-computations-3] s.d.c.r.q.ReactiveAbstractN1qlBasedQuery : Executing N1QL query: {“args”:[“eb991882-59f8-40e7-91d0-5b4a9d051c5b”],“statement”:"SELECT META(prices).id AS _ID, META(prices).cas AS _CAS, prices.* FROM prices WHERE (pciId = $1) AND _class =“XXXXXX”,“scan_consistency”:“request_plus”}

Couchbase server: 6.0.2
spring-data-couchbase-reactive: 2.2.1 (couchbase-core-io:1.7.9, couchbase-java-client:2.7.9)


Hi @sri_ram

The QueryOptions block, like all the SDK options blocks, is not thread-safe.

Though this doesn’t sound like a thread-safety issue anyway, this sounds like you maybe have a shared QueryOptions block that you are customising the parameters of just before performing the query? In which case this is a race that would exist regardless if the QueryOptions were thread safe.

This is more of a mutability concern. You need to create a QueryOptions object per query, if you’re making any changes to it. Modifying a QueryOptions (e.g. by setting the parameters) does not return a new immutable copy, it’s directly mutating the object.