<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Resolve deadlocks in CAP Node.JS app in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553294#M4706771</link>
    <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;onnheimc&lt;/SPAN&gt; ,&lt;/P&gt;&lt;P&gt;Thanks for your detailed response! &lt;/P&gt;&lt;P&gt;&amp;gt; Regarding the "outbox":false part it will, if I understand correctly, only affect the filling of the queues? &lt;BR /&gt;&lt;BR /&gt;Exactly, that was just to make sure that all messages are emitted correctly.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; regarding the incomingSessionWindow, I would assume it has similar throttling effects as the maxDeliveredUnackedMsgsPerFlow?&lt;/P&gt;&lt;P&gt;The option &lt;STRONG&gt;incomingSessionWindow&lt;/STRONG&gt; is used for the AMQP client, here we make sure that there won't be more messages in parallel than the specified ones.&lt;BR /&gt;&lt;BR /&gt;It's really hard to understand the root cause of this, maybe there are some problems with the connection pool (too many 'blocked' connections), hard to tell. It's strange that it seems to work for hdb but not for  @sap/hana-client. Maybe the underlying driver has some problems, I will investigate.&lt;BR /&gt;&lt;BR /&gt;For the time being, can you switch to hdb? That is our preferred choice anyway.&lt;/P&gt;&lt;P&gt;Thanks and best regards,&lt;BR /&gt;David&lt;/P&gt;</description>
    <pubDate>Mon, 14 Feb 2022 08:59:07 GMT</pubDate>
    <dc:creator>david_kunz2</dc:creator>
    <dc:date>2022-02-14T08:59:07Z</dc:date>
    <item>
      <title>Resolve deadlocks in CAP Node.JS app</title>
      <link>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaq-p/12553282</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
  &lt;P&gt;I am having issues with deadlocks when processing Event Mesh messages in a CAP Node.js application. We have the following context:&lt;/P&gt;
  &lt;UL&gt;
   &lt;LI&gt;A single queue is receiving frequent messages&lt;/LI&gt;
   &lt;LI&gt;The queue emits 10 concurrent messages to increase throughput&lt;/LI&gt;
   &lt;LI&gt;The queue will retry each message 3 times, since our scenarios often have transient errors&lt;/LI&gt;
  &lt;/UL&gt;
  &lt;P&gt;This runs fine most of the time, but I run into deadlocks if/when the error rate increases. We are in essence doing this:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;messaging.on('sometopic', async (msg) =&amp;gt; {
//... our stuff which locks certain db resources and may throw errors
//... we do not make any "cds.tx" handling or so (done by the framework to our understanding)
});&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;We can see the locks in the database monitor when it stalls, looking like this:&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2017651-deadlocks.jpg" /&gt;&lt;/P&gt;
  &lt;P&gt;What surprises me is that there is an idle session which blocks the ones trying to lock an actual resource. I am suspecting that I am somehow preventing one message processing attempt from cleaning up before the retry comes in and tries to lock the same resources.&lt;/P&gt;
  &lt;P&gt;Is there a way to trace from e.g. the Logical Connection ID (marked 239984 in the scenario above) to which cds transaction it is that started it?&lt;/P&gt;
  &lt;P&gt;Hoping somebody has advice on how to isolate the root cause in this situation.&lt;/P&gt;
  &lt;P&gt;Thanks!&lt;/P&gt;
  &lt;P&gt;//Carl&lt;/P&gt;</description>
      <pubDate>Mon, 07 Feb 2022 01:23:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaq-p/12553282</guid>
      <dc:creator>carlonnheim</dc:creator>
      <dc:date>2022-02-07T01:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve deadlocks in CAP Node.JS app</title>
      <link>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553283#M4706760</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;onnheimc&lt;/SPAN&gt; ,&lt;/P&gt;&lt;P&gt;Thanks for reporting this issue!&lt;/P&gt;&lt;P&gt;I think it would be helpful if you could log the database statements which are sent to the database.&lt;BR /&gt;You can enable them by setting the environment variable &lt;STRONG&gt;DEBUG=hana&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;In your handlers, it is sufficient to write &lt;STRONG&gt;await INSERT.into(xxx)&lt;/STRONG&gt; or &lt;STRONG&gt;await SELECT.from(xxx)&lt;/STRONG&gt; without &lt;STRONG&gt;cds.tx(msg)&lt;/STRONG&gt;, we will automatically commit the statements when all handlers are successfully executed. But we should make sure that this is indeed happening by looking at the logs.&lt;BR /&gt;&lt;BR /&gt;Thanks and best regards,&lt;BR /&gt;David&lt;/P&gt;</description>
      <pubDate>Mon, 07 Feb 2022 07:47:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553283#M4706760</guid>
      <dc:creator>david_kunz2</dc:creator>
      <dc:date>2022-02-07T07:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve deadlocks in CAP Node.JS app</title>
      <link>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553284#M4706761</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;david.kunz2&lt;/SPAN&gt; ,&lt;/P&gt;&lt;P&gt;Thanks for the suggestion. I am trying to trace the issue this way. Having DEBUG=hana activated does not show the transaction details though and I do not see anything obvious from the sequence of SQL statements.&lt;/P&gt;&lt;P&gt;I did add some logging to  @sap/cds/libx/_runtime/db/Services.js to tag each connection with the transaction identifier I have from the cds context. E.g. doing this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;  /*
   * tx
   */
  async begin() {
    const tx = this.context ? this : this.tx()
    tx.dbc = await tx.acquire(tx.context)
    try {
tx.dbc.setClientInfo('APPLICATION', tx.context.id);
console.log("************BEGIN", tx.context.id);
        await tx.send('BEGIN')
    } catch (e) {
      tx.release(tx.dbc)
      throw e
    }
    return tx
  }

  async commit() {
    // only release on successful commit as otherwise released on rollback
console.log("************COMMIT", this.context.id);
    await this.send('COMMIT')
    this.release(this.dbc)
  }

  async rollback() {
    if (this.dbc) {
      try {
console.log("************ROLLBACK", this.context.id);
        await this.send('ROLLBACK')
      } finally {
        this.release(this.dbc)
      }
    }
  }
&lt;/CODE&gt;&lt;/PRE&gt;Now I can see the transactions starting and stopping but it is still difficult to see which statements to the DB goes into which transaction.It does help me narrow down the attributes of the scenario. It seems I need these ingredients for it to happen:&lt;UL&gt;&lt;LI&gt;Several messages locking the same resources&lt;/LI&gt;&lt;LI&gt;Activities within one transaction processing deeply nested structures&lt;/LI&gt;&lt;LI&gt;The messages fail to complete and the failures are coming at the COMMIT-stage (e.g. ASSERT_REFERENCE_INTEGRITY coming from CDS)&lt;/LI&gt;&lt;LI&gt;Using several async/await patterns and/or Promises throughout the message processing logic&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I have tried reproducing the issue in a clean application (having all of the above, but stripped of complexity) so I could share that here, but I am not able to reproduce the lock in such a setting.&lt;/P&gt;&lt;P&gt;I am now suspecting that either my application code is somehow detaching its "async" chain (a missing await somewhere or so) causing some of the queries to fall out into a new transaction which I do not close, or there is something not going right with the CDS assertions to keep the transactions from closing properly.&lt;/P&gt;&lt;P&gt;Is it possible somehow to get a trace of which SQL statements go into which connection on the CAP side? Is it possible to trace on the HANA Cloud side which statements have actually been run on a connection (so I could see where the ones idling but still blocking others are stuck)?&lt;/P&gt;&lt;P&gt;Many thanks in advance!&lt;/P&gt;&lt;P&gt;//Carl&lt;/P&gt;</description>
      <pubDate>Mon, 07 Feb 2022 23:34:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553284#M4706761</guid>
      <dc:creator>carlonnheim</dc:creator>
      <dc:date>2022-02-07T23:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve deadlocks in CAP Node.JS app</title>
      <link>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553285#M4706762</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;onnheimc&lt;/SPAN&gt; ,&lt;/P&gt;&lt;P&gt;Thanks for this additional information!&lt;/P&gt;&lt;P&gt;It's strange that DEBUG=hana doesn't show the SQL statements, that really should be the case. How did you set the DEBUG variable? Locally or on Cloud Foundry (via cf set-env &amp;lt;app-name&amp;gt; DEBUG hana)? Can you make sure that it's correctly set by printing process.env.DEBUG in your Node.js process?&lt;BR /&gt;&lt;BR /&gt;&amp;gt; I am now suspecting that either my application code is somehow detaching its "async" chain&lt;/P&gt;&lt;P&gt;This is one of the most frequent error causes of applications, you need to make sure to not break the Promise chain, otherwise there will be race conditions.&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;BR /&gt;David&lt;/P&gt;</description>
      <pubDate>Tue, 08 Feb 2022 06:45:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553285#M4706762</guid>
      <dc:creator>david_kunz2</dc:creator>
      <dc:date>2022-02-08T06:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve deadlocks in CAP Node.JS app</title>
      <link>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553286#M4706763</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;david.kunz2&lt;/SPAN&gt; ,&lt;/P&gt;&lt;P&gt;It shows the SQL conditions but not the details of the transactions. I do not see the actual "BEGIN" and "COMMIT" in the log (until I added those logging statements) and I cannot see how they group together (which SQL statement is run in which connection/transaction).&lt;/P&gt;&lt;P&gt;Is there a good way to get this logged? Looking at what comes out now I see one of the message handlers coming to its COMMIT but then it does not proceed. It seems to be "trickle-feeding" statements to do the data integrity assertions (i.e. it selects on the "association to ..." tables to verify the foreign keys), but then it is not moving on. Could there be a need to flush buffers or something which my scenario somehow clogs up?&lt;/P&gt;&lt;P&gt;Can I for example catch the hana client connection when it has been set up? If so I could turn on tracing there using &lt;A href="https://help.sap.com/viewer/f1b440ded6144a54ada97ff95dac7adf/2.11/en-US/69b75ee358504c8089d762c240e31da8.html?q=onTrace"&gt;onTrace&lt;/A&gt; to see what is going on? I am suspecting that even though my code reaches the "send('COMMIT')" statement above, that commit is not actually reaching the DB (it is doing the CDS assertions first and seems to be stuck there)?&lt;/P&gt;&lt;P&gt;Have I understood the processing chain of the framework correctly?&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Event comes in, framework sets up context, transaction etc. and starts running the handlers&lt;/LI&gt;&lt;LI&gt;Handlers run (my application code)&lt;/LI&gt;&lt;LI&gt;Framework rolls back if any handler throws&lt;/LI&gt;&lt;LI&gt;Framework commits otherwise&lt;/LI&gt;&lt;LI&gt;On commit, the CDS framework will first do data consistency validations and then commit to the DB or roll back if anything fails. So an "application layer commit" before the DB-commit?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;If that is correct, I think the lock is happening in the last step. Any advice on where I would start placing breakpoints to trace the transactions through there?&lt;/P&gt;&lt;P&gt;Many thanks for your help and support!&lt;/P&gt;&lt;P&gt;//Carl&lt;/P&gt;</description>
      <pubDate>Tue, 08 Feb 2022 08:32:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553286#M4706763</guid>
      <dc:creator>carlonnheim</dc:creator>
      <dc:date>2022-02-08T08:32:37Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve deadlocks in CAP Node.JS app</title>
      <link>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553287#M4706764</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;onnheimc&lt;/SPAN&gt; ,&lt;/P&gt;&lt;P&gt;That is correct. Once your handlers execute successfully, we run the integrity checks and then perform a commit on the database (if they succeed), otherwise (handlers reject/throw or integrity checks fail) we perform a rollback.&lt;/P&gt;&lt;P&gt;It might be interesting to see what happens if you disable the integrity checks (for testing purposes).&lt;/P&gt;&lt;P&gt;Could you set cds.features.assert_integrity&lt;STRONG&gt;: 'db' &lt;/STRONG&gt;to disable runtime integrity checks?&lt;BR /&gt;If you want I can have a look at your code to see if there are some mistakes w.r.t. transaction handling/promises&lt;BR /&gt;(doesn't need to be answers.sap.com).&lt;/P&gt;&lt;P&gt;Best regards,&lt;BR /&gt;David&lt;/P&gt;</description>
      <pubDate>Tue, 08 Feb 2022 08:46:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553287#M4706764</guid>
      <dc:creator>david_kunz2</dc:creator>
      <dc:date>2022-02-08T08:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve deadlocks in CAP Node.JS app</title>
      <link>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553288#M4706765</link>
      <description>&lt;P&gt;Hi David,&lt;/P&gt;&lt;P&gt;I also see the difference that when you're using sqlite and DEBUG=sqlite the begin of the transaction as well as the commit are shown in the log. But for HANA this is not the case. Would be great if this can be fixed soon. If needed I can file an Incident.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;CU&lt;BR /&gt;Gregor&lt;/P&gt;</description>
      <pubDate>Tue, 08 Feb 2022 09:20:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553288#M4706765</guid>
      <dc:creator>gregorw</dc:creator>
      <dc:date>2022-02-08T09:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve deadlocks in CAP Node.JS app</title>
      <link>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553289#M4706766</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;david.kunz2&lt;/SPAN&gt; ,&lt;/P&gt;&lt;P&gt;Thanks for the offer to help reviewing code. I started preparing a cleaned up sample of our issue to enable that. In doing so I also got closer to the root cause - it seems the issue comes from the @sap/hana-client package. I do not get any deadlocks when using the hdb module in its place.&lt;/P&gt;&lt;P&gt;The former module is the long term path from what I understand, so we should try to find a solution?&lt;/P&gt;&lt;P&gt;I have put the code demonstrating the issue &lt;A href="https://github.com/carlonnheim/cap-msg-deadlock"&gt;here&lt;/A&gt;. If you run the scenarios there with the hdb module it works fine (except cds seems to swallow throws without a proper error parameter - but this we can of course just make sure to not do...). If you then take the hdb module out and run with @sap/hana-client instead it will start deadlocking (at least it does for me).&lt;/P&gt;&lt;P&gt;Hoping this is possible to reproduce on your end and that somebody with insight into the hana-client module can take a look? I tried tracing through that but got out of my depth...&lt;/P&gt;&lt;P&gt;Again, thanks for the support!&lt;/P&gt;&lt;P&gt;//Carl&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 20:29:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553289#M4706766</guid>
      <dc:creator>carlonnheim</dc:creator>
      <dc:date>2022-02-09T20:29:17Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve deadlocks in CAP Node.JS app</title>
      <link>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553290#M4706767</link>
      <description>&lt;P&gt;Hi &lt;SPAN class="mention-scrubbed"&gt;gregorw&lt;/SPAN&gt; ,&lt;BR /&gt;&lt;BR /&gt;Indeed, I quickly looked over our code to check why this is the case, it might be related to some auto commit functionality, but I will check in more detail why we don't log the transaction information using HANA and see if we can enable that!&lt;/P&gt;&lt;P&gt;Hi &lt;SPAN class="mention-scrubbed"&gt;onnheimc&lt;/SPAN&gt; ,&lt;/P&gt;&lt;P&gt;Thanks a lot for showcasing this error! I think the problem is that you are not creating a right context when using plain express middleware, let me explain that in more details:&lt;/P&gt;&lt;P&gt;Usually, one registers CAP handlers (not express middleware). The main difference is that in CAP handlers, we construct a request object and an &lt;A href="https://nodejs.org/api/async_hooks.html#class-asynclocalstorage"&gt;async local storage&lt;/A&gt; called &lt;STRONG&gt;cds.context &lt;/STRONG&gt;where we keep track of the main transaction. After CAP executed all registered CAP handlers, we emit a succeeded event. If a database service was involved, a COMMIT is triggered. Whenever you run &lt;STRONG&gt;await INSERT.into(xxx)&lt;/STRONG&gt; or other statements, we use &lt;STRONG&gt;cds.context&lt;/STRONG&gt; to link that operation to the current main transaction.&lt;/P&gt;&lt;P&gt;Now in your case: You use express middleware, that means we didn't construct a proper request object as well as cds.context. We also won't perform any succeeded events because the generic code is not run. Or in other words: In express middlewares you're completely responsible for transaction management.&lt;/P&gt;&lt;P&gt;What you can use instead is create a manual transaction using&lt;/P&gt;&lt;P&gt;cds.tx(async tx =&amp;gt; {&lt;/P&gt;&lt;P&gt;  tx.run(INSERT.into(xxx))&lt;/P&gt;&lt;P&gt;})&lt;/P&gt;&lt;P&gt;, this will automatically be committed.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;You can have a look at &lt;A href="https://cap.cloud.sap/docs/node.js/transactions" target="_blank"&gt;https://cap.cloud.sap/docs/node.js/transactions&lt;/A&gt; for more details.&lt;/P&gt;&lt;P&gt;Best regards,&lt;BR /&gt;David&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 07:02:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553290#M4706767</guid>
      <dc:creator>david_kunz2</dc:creator>
      <dc:date>2022-02-10T07:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve deadlocks in CAP Node.JS app</title>
      <link>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553291#M4706768</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;david.kunz2&lt;/SPAN&gt; ,&lt;/P&gt;&lt;P&gt;Thanks for your fast responses!&lt;/P&gt;&lt;P&gt;We are only using express for its routing capabilities here actually, not as middleware. The background of that is that we get all notifications from our source system (SAP Business ByDesign) on one topic in the form of "cloudevents" where a "type" member in the header indicates what happened (which object, create/update/delete etc.). This way I can leverage the routing capability of express to trigger the right processing of each message, use its query parameter handling capabilities etc. In short, I create a pretend-request, pass it to the router and wrap it in a Promise which completes after the routing finishes.&lt;/P&gt;&lt;P&gt;Quite useful in this scenario, but actually unrelated to the locking issue. I included it in the sample code because I also suspected the broken promise chain to came from there, but the same issues occur without it. I have cut this part out of the sample repo now so it goes straight in the regular CAP handler.&lt;/P&gt;&lt;P&gt;I also put a branch "&lt;A href="https://github.com/carlonnheim/cap-msg-deadlock/tree/simple"&gt;simple&lt;/A&gt;" there with just the main scenario and with the @sap/hana-client library in use. It boils down to this&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;const cds = require('@sap/cds');

module.exports = async srv =&amp;gt; {
    const messaging = await cds.connect.to("messaging");

    // Simulate locking of a common resource for one second on each message receipt
    messaging.on('default/my/service/locktest', async msg =&amp;gt; {
        const db = await cds.connect.to('db');
        const { Lock, RelatedResource } = db.entities('eventmesh');
        console.log('MSG IN: ', JSON.stringify(msg));
        // Lock a common resource for 1 second, then succeed
        var r = { resource: msg.data.same }
        await INSERT.into(Lock, r);
        await DELETE.from(Lock, r);
        await new Promise((resolve, reject) =&amp;gt; setTimeout(resolve, 1000));
    });

    // Emit a bunch of messages
    var payloads = [];
    for (var i = 0; i &amp;lt; 25; i++) payloads.push({ same: 'A', different: i.toString(), often: (i % 3).toString() });
    var promises = payloads.map(x =&amp;gt; messaging.emit('default/my/service/locktest', x, x));
    await Promise.all(promises);
}&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This should work I think (serializing the requests over the common resource, effectively coming through one message per second), but it locks up. Running it with hdb instead of @sap/hana-client gives the expected result.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;//Carl&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 09:33:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553291#M4706768</guid>
      <dc:creator>carlonnheim</dc:creator>
      <dc:date>2022-02-10T09:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve deadlocks in CAP Node.JS app</title>
      <link>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553292#M4706769</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;onnheimc&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;Yes, this is better. I wonder if there might be too much load on the database and acquiring a client will cause troubles.&lt;/P&gt;&lt;P&gt;Can you set &lt;/P&gt;&lt;P&gt;   "amqp": {
              "incomingSessionWindow": 10
            }&lt;/P&gt;&lt;P&gt;in your messaging service configuration? That will force Event Mesh to only send 10 concurrent messages to your app.&lt;/P&gt;&lt;P&gt;After that, can you also set&lt;/P&gt;&lt;P&gt;"outbox": false&lt;/P&gt;&lt;P&gt;in your messaging service configuration. Otherwise a `await messaging.emit(...)` doesn't actually perform the emit, it only waits until the transaction is succeeded and then emits the messages.&lt;/P&gt;&lt;P&gt;Thanks and best regards,&lt;BR /&gt;David&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 09:43:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553292#M4706769</guid>
      <dc:creator>david_kunz2</dc:creator>
      <dc:date>2022-02-10T09:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve deadlocks in CAP Node.JS app</title>
      <link>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553293#M4706770</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;david.kunz2&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;Thanks for these suggestions. I have tried them but unfortunately had no effect on the locks&lt;/P&gt;&lt;P&gt;Regarding the "outbox":false part it will, if I understand correctly, only affect the filling of the queues? I get the same locks in my deployed scenarios where the messages are filled in a bursty nature from an external system.&lt;/P&gt;&lt;P&gt;Regarding the incomingSessionWindow, I would assume it has similar throttling effects as the maxDeliveredUnackedMsgsPerFlow? I have been using that so far to set different levels of concurrency in the tests. I did some more experiments with those parameters today, concluding:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;No locks with low level of concurrency. If I have maxDeliveredUnackedMsgsPerFlow lower than 5 the process seem to flow nicely.&lt;/LI&gt;&lt;LI&gt;If I go beyond 5 concurrent processors the locks start to appear. The lower the concurrency the shorter the duration of the locks it seems. What I mean by that is that I can clearly see the locks appear (the throughput stalls) but it is also resolving after some time (some 10 seconds), keeps eating one message per second for a while, stalls again and so on.&lt;/LI&gt;&lt;LI&gt;When I get to ~10 concurrent processors it locks down much harder. These remain until the DB times out the lock acquisitions.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I should also mention that when in the locked state, the node process will not respond to a regular kill signal (Ctrl+C has no effect). It will go down on a "kill -9" but it does not clean up resources (the locks are still in the DB and the network socket remains open - it is noticed when restarting the service again which stops due to a address-in-use). The way I have found to clean up from this state is cancelling the locked sessions on the HANA side. Oddly enough, the lock resolves when I have cancelled the last session waiting to acquire the lock, while trying to cancel the one that actually holds the locks has no effect. Maybe there is a clue to the root cause in that patter?&lt;/P&gt;&lt;P&gt;Since all the scenarios work flawlessly using the hdb driver I think this must be looked at by somebody with insight to the @sap/hana-client. I am happy to engage in this, join troubleshooting sessions etc. if that helps?&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;//Carl&lt;/P&gt;</description>
      <pubDate>Sun, 13 Feb 2022 10:37:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553293#M4706770</guid>
      <dc:creator>carlonnheim</dc:creator>
      <dc:date>2022-02-13T10:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve deadlocks in CAP Node.JS app</title>
      <link>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553294#M4706771</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;onnheimc&lt;/SPAN&gt; ,&lt;/P&gt;&lt;P&gt;Thanks for your detailed response! &lt;/P&gt;&lt;P&gt;&amp;gt; Regarding the "outbox":false part it will, if I understand correctly, only affect the filling of the queues? &lt;BR /&gt;&lt;BR /&gt;Exactly, that was just to make sure that all messages are emitted correctly.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; regarding the incomingSessionWindow, I would assume it has similar throttling effects as the maxDeliveredUnackedMsgsPerFlow?&lt;/P&gt;&lt;P&gt;The option &lt;STRONG&gt;incomingSessionWindow&lt;/STRONG&gt; is used for the AMQP client, here we make sure that there won't be more messages in parallel than the specified ones.&lt;BR /&gt;&lt;BR /&gt;It's really hard to understand the root cause of this, maybe there are some problems with the connection pool (too many 'blocked' connections), hard to tell. It's strange that it seems to work for hdb but not for  @sap/hana-client. Maybe the underlying driver has some problems, I will investigate.&lt;BR /&gt;&lt;BR /&gt;For the time being, can you switch to hdb? That is our preferred choice anyway.&lt;/P&gt;&lt;P&gt;Thanks and best regards,&lt;BR /&gt;David&lt;/P&gt;</description>
      <pubDate>Mon, 14 Feb 2022 08:59:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553294#M4706771</guid>
      <dc:creator>david_kunz2</dc:creator>
      <dc:date>2022-02-14T08:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve deadlocks in CAP Node.JS app</title>
      <link>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553295#M4706772</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;david.kunz2&lt;/SPAN&gt; ,&lt;/P&gt;&lt;P&gt;Yes, I have already switched to hdb in our development version. But I got the understanding that @sap/hana-client was the preferred choice (from the docs &lt;A href="https://www.npmjs.com/package/hdb#sap-support-for-hdb-and-saphana-client"&gt;here&lt;/A&gt;).&lt;/P&gt;&lt;P&gt;That is why I was thinking that @sap/hana-client should be the library to use, hence important to get to the bottom of this issue. Is hdb actually the preferred choice? I cannot see any difference in how our apps run, works the same way independent of which one I use, but I want to stay on the "golden path" in general.&lt;/P&gt;&lt;P&gt;I am entering the test phase with this project, so would be great to know what gives - if the recommended way is hdb then I'll just consider that switch permanent and move on (the issue above is still curious, but nothing more...).&lt;/P&gt;&lt;P&gt;I would also suggest to update the documentation if this is the case. The link above and &lt;A href="https://help.sap.com/viewer/f1b440ded6144a54ada97ff95dac7adf/2.11/en-US/a5c332936d9f47d8b820a4ecc427352c.html"&gt;this one&lt;/A&gt; for example directs to @sap/hana-client.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;//Carl&lt;/P&gt;</description>
      <pubDate>Mon, 14 Feb 2022 09:28:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553295#M4706772</guid>
      <dc:creator>carlonnheim</dc:creator>
      <dc:date>2022-02-14T09:28:56Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve deadlocks in CAP Node.JS app</title>
      <link>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553296#M4706773</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;onnheimc&lt;/SPAN&gt; ,&lt;/P&gt;&lt;P&gt;Yes, they write it in their documentation, those extra features are typically not needed if you use it in your CAP app.&lt;/P&gt;&lt;P&gt;For CAP, hdb is the preferred choice.&lt;/P&gt;&lt;P&gt;Best regards,&lt;BR /&gt;David&lt;/P&gt;</description>
      <pubDate>Mon, 14 Feb 2022 09:34:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553296#M4706773</guid>
      <dc:creator>david_kunz2</dc:creator>
      <dc:date>2022-02-14T09:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve deadlocks in CAP Node.JS app</title>
      <link>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553297#M4706774</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;david.kunz2&lt;/SPAN&gt; ,&lt;/P&gt;&lt;P&gt;Have been running on hdb for some time now, much smoother - thanks!&lt;/P&gt;&lt;P&gt;One question tough; I am starting to get "Decimal" datatypes read back from the DB in scientific notation (e.g. '1.01e+3' instead of '1010' (which earlier also used to come as a string, not not in scientific notation). Is this the expected behavior from hdb?&lt;/P&gt;&lt;P&gt;We have a lot of integrations with ByD which accepts string-but-not-scientific formatted decimals. Can I control this behavior centrally somehow (e.g. config option)?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;//Carl&lt;/P&gt;</description>
      <pubDate>Thu, 17 Feb 2022 18:52:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553297#M4706774</guid>
      <dc:creator>carlonnheim</dc:creator>
      <dc:date>2022-02-17T18:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve deadlocks in CAP Node.JS app</title>
      <link>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553298#M4706775</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;onnheimc&lt;/SPAN&gt; ,&lt;/P&gt;&lt;P&gt;That's good to hear, glad it works better with hdb!&lt;/P&gt;&lt;P&gt;Regarding the decimals: There's the HTTP header IEEE754Compatible=true/false but I'm not sure if it helps in your case, could you kindly try it out?&lt;BR /&gt;&lt;BR /&gt;Thanks and best regards,&lt;BR /&gt;David&lt;/P&gt;</description>
      <pubDate>Fri, 18 Feb 2022 07:43:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553298#M4706775</guid>
      <dc:creator>david_kunz2</dc:creator>
      <dc:date>2022-02-18T07:43:20Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve deadlocks in CAP Node.JS app</title>
      <link>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553299#M4706776</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;david.kunz2&lt;/SPAN&gt; ,&lt;/P&gt;&lt;P&gt;I am not getting them via HTTP calls but rather when I do like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;var myObject = await SELECT.from(MyEntityWithDecimalProperty, { id: 123 });&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So I was thinking (hoping) there is some configuration parameters (cds.requires...) which would give me decimals back in non-scientific notation. Now I need to do like so in a lot of places&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;// myObject.someDecimal is '1.01e+3'
myObject.someDecimal = Number(myObject.someDecimal).toString()
// myObject.someDecimal is '1010' (still a string, but not scientific notation)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;//Carl&lt;/P&gt;</description>
      <pubDate>Fri, 18 Feb 2022 08:29:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553299#M4706776</guid>
      <dc:creator>carlonnheim</dc:creator>
      <dc:date>2022-02-18T08:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve deadlocks in CAP Node.JS app</title>
      <link>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553300#M4706777</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;onnheimc&lt;/SPAN&gt; ,&lt;/P&gt;&lt;P&gt;Could you declare precision and scale for that field? &lt;/P&gt;&lt;P&gt;E.g. Decimal(16, 3)? Then it shouldn't return it in scientific notation.&lt;/P&gt;&lt;P&gt;Best regards,&lt;BR /&gt;David&lt;/P&gt;</description>
      <pubDate>Fri, 18 Feb 2022 09:16:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/resolve-deadlocks-in-cap-node-js-app/qaa-p/12553300#M4706777</guid>
      <dc:creator>david_kunz2</dc:creator>
      <dc:date>2022-02-18T09:16:12Z</dc:date>
    </item>
  </channel>
</rss>

