# Caller=server.go:349 level=error msg="Failed to write data to CrateDB" err="error closing write batch: timeout: context deadline exceeded"

**URL:** <https://community.cratedb.com/t/caller-server-go-349-level-error-msg-failed-to-write-data-to-cratedb-err-error-closing-write-batch-timeout-context-deadline-exceeded/1809>\
**Category:** CrateDB\
**Tags:** prometheus\
**Created:** [July 17, 2024, 2:21pm UTC](https://community.cratedb.com/t/caller-server-go-349-level-error-msg-failed-to-write-data-to-cratedb-err-error-closing-write-batch-timeout-context-deadline-exceeded/1809 "2024-07-17T14:21:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tsgaah](https://avatars.discourse-cdn.com/v4/letter/t/dbc845/32.png) [@tsgaah](https://community.cratedb.com/u/tsgaah)\
**Post date:** [July 17, 2024, 2:21pm UTC](https://community.cratedb.com/t/caller-server-go-349-level-error-msg-failed-to-write-data-to-cratedb-err-error-closing-write-batch-timeout-context-deadline-exceeded/1809/1 "2024-07-17T14:21:39Z")

</div>

Have configured a single node CrateDB cluster with cratedb-prometheus-adapter as a proof of concept for LTS of Prometheus metrics.

The following error is produced after starting the adapter:

caller=server.go:349 level=error msg=“Failed to write data to CrateDB” err=“error closing write batch: timeout: context deadline exceeded”

Here are the versions in play:  
Prometheus - 2.36.2  
CrateDB Prometheus Adapter - 0.5.1  
CrateDB version - 5.7.1-1

And here is the adapter config:

cratedb\_endpoints:

- host: xx.xx.xx.xx  
port: 5432  
user: admin  
password: “xxxxx”  
schema: “”  
max\_connections: 0  
read\_pool\_size\_max: 0  
write\_pool\_size\_max: 0  
connect\_timeout: 10  
read\_timeout: 5  
write\_timeout: 5  
enable\_tls: false  
allow\_insecure\_tls: false

Any suggestions what can be tuned?

---

<div class="post-metadata">

**Author:** ![surister](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/surister/32/1087_2.png) [@surister](https://community.cratedb.com/u/surister)\
**Post date:** [July 17, 2024, 2:41pm UTC](https://community.cratedb.com/t/caller-server-go-349-level-error-msg-failed-to-write-data-to-cratedb-err-error-closing-write-batch-timeout-context-deadline-exceeded/1809/2 "2024-07-17T14:41:09Z")

</div>

Could you check that:  
[1] CrateDB is up and running  
[2] CrateDB is reachable from where `cratedb-prometheus-adapter` is being run with the same credentials?

---

<div class="post-metadata">

**Author:** ![tsgaah](https://avatars.discourse-cdn.com/v4/letter/t/dbc845/32.png) [@tsgaah](https://community.cratedb.com/u/tsgaah)\
**Post date:** [July 17, 2024, 3:12pm UTC](https://community.cratedb.com/t/caller-server-go-349-level-error-msg-failed-to-write-data-to-cratedb-err-error-closing-write-batch-timeout-context-deadline-exceeded/1809/3 "2024-07-17T15:12:20Z")

</div>

Hi, yes, CrateDB is up and reachable. We do have a large number of metrics already ingested; however, the adapter seems to baulk after approx 20 seconds.

---

<div class="post-metadata">

**Author:** ![surister](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/surister/32/1087_2.png) [@surister](https://community.cratedb.com/u/surister)\
**Post date:** [July 17, 2024, 3:31pm UTC](https://community.cratedb.com/t/caller-server-go-349-level-error-msg-failed-to-write-data-to-cratedb-err-error-closing-write-batch-timeout-context-deadline-exceeded/1809/4 "2024-07-17T15:31:12Z")

</div>

1. You start the program, it ingests correctly and after 20s you get the timeouts.
2. While you are getting the timeouts, CrateDB is reachable from the service’s environment, issuing for example a “SELECT 1;” returns alright.

Are these two assertions correct?

While you are getting the timeouts, is there anything weird in the admin UI graphs? No peaks? Red shards or alerts?

---

<div class="post-metadata">

**Author:** ![amotl](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/amotl/32/617_2.png) [@amotl](https://community.cratedb.com/u/amotl)\
**Post date:** [July 17, 2024, 3:54pm UTC](https://community.cratedb.com/t/caller-server-go-349-level-error-msg-failed-to-write-data-to-cratedb-err-error-closing-write-batch-timeout-context-deadline-exceeded/1809/5 "2024-07-17T15:54:32Z")

</div>

Dear Tony,

thank you for writing in. I think we had a similar report at [Failed to POST/GET data from CrateDB: Croaks with err="context deadline exceeded" · Issue #33 · crate/cratedb-prometheus-adapter · GitHub](https://github.com/crate/cratedb-prometheus-adapter/issues/33). Therefore, we added the `connect_timeout`, `read_timeout`, and `write_timeout` options.

> [@tsgaah](#):
>
> connect\_timeout: 10  
> read\_timeout: 5  
> write\_timeout: 5

> [@tsgaah](#):
>
> The adapter seems to baulk after approx 20 seconds.

Can you try to increase the values for the `timeout` parameters so that the Prometheus Adapters does not quit the connection too early? When it’s taking too long to evaluate your query, you may need to optimize it, or your data schema / cluster configuration.

Please let us know if that improves the situation for you.

With kind regards,  
Andreas.

---

<div class="post-metadata">

**Author:** ![tsgaah](https://avatars.discourse-cdn.com/v4/letter/t/dbc845/32.png) [@tsgaah](https://community.cratedb.com/u/tsgaah)\
**Post date:** [July 18, 2024, 12:31pm UTC](https://community.cratedb.com/t/caller-server-go-349-level-error-msg-failed-to-write-data-to-cratedb-err-error-closing-write-batch-timeout-context-deadline-exceeded/1809/6 "2024-07-18T12:31:34Z")

</div>

The assertions are correct. I’ve increased the connect\_timeout, read\_timeout and write\_timeout values which has helped massively.

The server running CrateDB and the adapter is behind multiple firewalls and I don’t have access to the UI. Are there SQL queries I can run to capture CrateDB performance stats?

---

<div class="post-metadata">

**Author:** ![tsgaah](https://avatars.discourse-cdn.com/v4/letter/t/dbc845/32.png) [@tsgaah](https://community.cratedb.com/u/tsgaah)\
**Post date:** [July 18, 2024, 12:33pm UTC](https://community.cratedb.com/t/caller-server-go-349-level-error-msg-failed-to-write-data-to-cratedb-err-error-closing-write-batch-timeout-context-deadline-exceeded/1809/7 "2024-07-18T12:33:25Z")

</div>

Thanks Andreas, increasing connect\_timeout, read\_timeout and write\_timeout values has improved things. I’ve only captured a single error in a hour with ingestion at the same rate. I’ll continue to tweak the parameters and monitor.
