Thread

  1. PostgreSQL 17.4 bug with JSON+UUID under high load

    Constantine Plotnikov <constantine.plotnikov@gmail.com> — 2025-03-31T08:38:37Z

    Hello!
    
    When writing some sample code that generates JSON from PostgreSQL, I
    encountered invalid formatting of UUIDs in JSON. The generated UUID are in
    truncated form like "0195e993-10". The problem happens under following
    conditions:
    
    * Generated JSON is fairly large (around 12M in my case, 1.2M almost never
    happens)
    
    * A lot of connections (40 in my case, for 10 everything was ok)
    
    * Program works for long time (7 minutes almost always errors, 1 minute
    almost never)
    
    I think the problem is important, as incorrect data is silently returned.
    It would have been better if postgresql just crashed.
    
    The sample code that reproduces the problem is at
    https://github.com/const/pg-json-uuid-bug. The README.adoc at the root
    contains a detailed description.
    
    The bug was originally detected in official docker image postgres:17.2, but
    it still reproduces in postgres:17.4.
    
    Environment:
    
    * Window 10 Pro 22H2
    
    * Docker Engine v27.5.1
    
    * PostgreSQL 17.4 (Debian 17.4-1.pgdg120+2) on x86_64-pc-linux-gnu,
    compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
    
    * CPU: 13th Gen Intel(R) Core(TM) i9-13900K   3.00 GHz
    
    * 128M memory
    
    * Java 21 + PG JDBC  42.7.5 (the test application was run from IDEA) - it
    should not affect the bug, as I just use "rs.getString(1)" to get JSON as
    java.lang.String.
    
    I do not know the real cause of the bug. PG is a primary suspect, maybe too
    aggressive optimizations in GCC are used, or here is some memory management
    error. Possibly, the bug is related to the bugs in 13th Gen Intel CPUs (but
    in this case more interesting bugs are expected, not just UUIDs).
    
    Best regards, Konstantin Plotnikov