Npsql timing out binary import (COPY binary) on windows hosted postgres timescale server

  .net-core, postgresql, timescaledb, windows

Hi I am having a problem executing a copy binary call to a postgres timescale server hosted on windows. The copy binary operation is abstracted away as binaryimport with the NpSql library for .Net.

I used a docker container running the latest-12 docker image for timescale db during development which worked perfectly fine, but I have had a lot of problems after trying to deploy postgres on windows.

I am able to start the copy operation and copy exactly 72539 rows. The data is gathered from an external api in chunks and there might be pauses in between adding new rows since some calls might return no data. Is it possible that the windows firewall closes the connection because of these pauses? If so how can I mitigate this?

Below is the stacktrace from my application and logs from the postgres server:

Npgsql.NpgsqlException (0x80004005): Exception while writing to stream
       ---> System.TimeoutException: Timeout during writing attempt
         at Npgsql.NpgsqlWriteBuffer.Flush(Boolean async, CancellationToken cancellationToken)
         at Npgsql.TypeHandling.NpgsqlSimpleTypeHandler`1.<>c__DisplayClass12_0`1.<<WriteWithLengthInternal>g__WriteWithLengthLong|0>d.MoveNext()
      --- End of stack trace from previous location ---
         at Npgsql.NpgsqlBinaryImporter.Write[T](T value, NpgsqlParameter param, Boolean async, CancellationToken cancellationToken)
         at Npgsql.NpgsqlBinaryImporter.WriteRow(Boolean async, CancellationToken cancellationToken, Object[] values)
2021-05-25 08:33:33.422 CEST [27136] ERROR:  unexpected EOF on client connection with an open transaction
2021-05-25 08:33:33.422 CEST [27136] CONTEXT:  COPY tag_log, line 72539, column log_value
2021-05-25 08:33:33.422 CEST [27136] STATEMENT:  COPY tag_log 

            (tag_id, log_ts, log_value) 

2021-05-25 08:33:33.429 CEST [27136] FATAL:  terminating connection because protocol synchronization was lost
2021-05-25 08:33:33.430 CEST [27136] LOG:  could not send data to client: An established connection was aborted by the software in your host machine.

Source: Windows Questions