Skip site navigation (1) Skip section navigation (2)

PGStream synchronization

From: Maciek Sakrejda <msakrejda(at)truviso(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: PGStream synchronization
Date: 2009-08-25 00:36:52
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc
We've found some synchronization issues around PGStream in
QueryExecutorImpl and ProtocolConnectionImpl. Specifically, while
QueryExecutorImpl synchronizes all its uses off PGStream,
ProtocolConnectionImpl uses the same PGStream directly when close() is
called. This can easily cause protocol-level errors and,
theoretically, at least, bad data shoved into a COPY IN query while
the actual Connection.close() is ignored. This doesn't just affect
COPY, though--anything that causes writes to the QueryExecutorImpl's
pgStream could be affected.

The only thing I've achieved so far is protocol-level errors, but
that's a serious enough issue on its own.

It's not immediately clear how to fix this, since we don't want to
synchronize PGStream itself. Should ProtocolConnectionImpl just
delegate to QueryExecutorImpl on close() perhaps, with
QueryExecutorImpl handling the actual writes to PGStream?

See sample code to reproduce below:

package com.truviso;

import java.sql.Connection;
import java.sql.DriverManager;

import org.postgresql.PGConnection;
import org.postgresql.copy.CopyIn;

public class Test {

    public static void main(String[] args) throws Exception {
        final PGConnection c = (PGConnection)
"foo", "");
            "drop table if exists foo; create temporary table foo(a text)");
        Thread t1 = new Thread(new Runnable() {
            public void run() {
                try {
                    CopyIn copy = c.getCopyAPI().copyInQuery("copy foo
from stdin");
                    String copyData = "abc";
                    byte[] copyBytes = copyData.getBytes();
                    copy.writeToCopy(copyBytes, 0, copyBytes.length);
                } catch (Exception e) {


Maciek Sakrejda | Software Engineer | Truviso

1065 E. Hillsdale Blvd., Suite 230
Foster City, CA 94404
(650) 242-3500 Main
(650) 242-3501 F


pgsql-jdbc by date

Next:From: Oliver JowettDate: 2009-08-25 00:48:04
Subject: Re: PGStream synchronization
Previous:From: Campbell, LanceDate: 2009-08-24 03:23:24
Subject: Re: Display SQL from Java Prepared Statement

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group