Multiple errors from Worker - "D1_ERROR: Network connection lost"

For Workes & Pages, what is the name of the domain?

it’s not necessary

What is the error number?

D1_ERROR

What is the error message?

Network connection lost

What is the issue or error you’re encountering

We have 1 million requests per day to Cloudflare Worker. This worker inserts information into the D1 database. ~1500 requests (from 1 million) can’t make a D1 request cause “D1_ERROR: Network connection lost” error.

What steps have you taken to resolve the issue?

Code sample:

this.db.prepare(
INSERT INTO analytics (storeId, barId, barType, event, host, pathName, eventDate, testIds) VALUES(?, ?, ?, ?, ?, ?, ?, ?)
).bind(storeId, barId, barType, event, host, pathName, eventDate, testIds).run();

I added a “Retries” feature around this request and now repeat the request 2 times with 1-second delay if it fails. Now we have ~60 errors per day.

What are the steps to reproduce the issue?

  1. Publish the application with 1 million requests per day
  2. Connect Sentry monitoring to Worker
  3. Make a D1 insert query per each request, wrap it with try/catch, and send errors to Sentry on “catch”