{"action":"created","issue":{"url":"https://api.github.com/repos/cockroachdb/cockroach/issues/7556","repository_url":"https://api.github.com/repos/cockroachdb/cockroach","labels_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/7556/labels{/name}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/7556/comments","events_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/7556/events","html_url":"https://github.com/cockroachdb/cockroach/issues/7556","id":163183304,"number":7556,"title":"Java deadlock in test with multiple simultaneous transactions","user":{"login":"archiecobbs","id":545866,"avatar_url":"https://avatars.githubusercontent.com/u/545866?v=3","gravatar_id":"","url":"https://api.github.com/users/archiecobbs","html_url":"https://github.com/archiecobbs","followers_url":"https://api.github.com/users/archiecobbs/followers","following_url":"https://api.github.com/users/archiecobbs/following{/other_user}","gists_url":"https://api.github.com/users/archiecobbs/gists{/gist_id}","starred_url":"https://api.github.com/users/archiecobbs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/archiecobbs/subscriptions","organizations_url":"https://api.github.com/users/archiecobbs/orgs","repos_url":"https://api.github.com/users/archiecobbs/repos","events_url":"https://api.github.com/users/archiecobbs/events{/privacy}","received_events_url":"https://api.github.com/users/archiecobbs/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"RaduBerinde","id":16544120,"avatar_url":"https://avatars.githubusercontent.com/u/16544120?v=3","gravatar_id":"","url":"https://api.github.com/users/RaduBerinde","html_url":"https://github.com/RaduBerinde","followers_url":"https://api.github.com/users/RaduBerinde/followers","following_url":"https://api.github.com/users/RaduBerinde/following{/other_user}","gists_url":"https://api.github.com/users/RaduBerinde/gists{/gist_id}","starred_url":"https://api.github.com/users/RaduBerinde/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RaduBerinde/subscriptions","organizations_url":"https://api.github.com/users/RaduBerinde/orgs","repos_url":"https://api.github.com/users/RaduBerinde/repos","events_url":"https://api.github.com/users/RaduBerinde/events{/privacy}","received_events_url":"https://api.github.com/users/RaduBerinde/received_events","type":"User","site_admin":false},"assignees":[{"login":"RaduBerinde","id":16544120,"avatar_url":"https://avatars.githubusercontent.com/u/16544120?v=3","gravatar_id":"","url":"https://api.github.com/users/RaduBerinde","html_url":"https://github.com/RaduBerinde","followers_url":"https://api.github.com/users/RaduBerinde/followers","following_url":"https://api.github.com/users/RaduBerinde/following{/other_user}","gists_url":"https://api.github.com/users/RaduBerinde/gists{/gist_id}","starred_url":"https://api.github.com/users/RaduBerinde/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RaduBerinde/subscriptions","organizations_url":"https://api.github.com/users/RaduBerinde/orgs","repos_url":"https://api.github.com/users/RaduBerinde/repos","events_url":"https://api.github.com/users/RaduBerinde/events{/privacy}","received_events_url":"https://api.github.com/users/RaduBerinde/received_events","type":"User","site_admin":false}],"milestone":null,"comments":8,"created_at":"2016-06-30T14:44:48Z","updated_at":"2016-07-01T00:56:14Z","closed_at":null,"body":"As part of a separate project, I'm running unit tests that check database behavior when conflicting and non-conflicting transactions are run at the same time.\r\n\r\nIn the case of CockroachDB, one of these tests deadlocks and hangs forever. Instead, some sort of retry exception should be thrown.\r\n\r\nInterestingly, it is a non-conflicting transaction test that is hanging (the conflicting transaction test is correctly throwing a retry exception).\r\n\r\nThe version I'm testing:\r\n```\r\nbuild:     beta-20160616 @ 2016/06/30 13:57:29 (go1.6.2)\r\nadmin:     http://localhost:9696\r\nsql:       postgresql://root@localhost:26257?sslmode=disable\r\nlogs:      /usr/local/var/cockroach/logs\r\nstore[0]:  path=/usr/local/var/cockroach\r\n```\r\nTest setup:\r\n```\r\nCREATE TABLE IF NOT EXISTS \"KV\" (\r\n  \"kv_key\" BYTES PRIMARY KEY NOT NULL,\r\n  \"kv_value\" BYTES NOT NULL\r\n);\r\nDELETE FROM \"KV\";\r\n```\r\n\r\nUnit test that hangs: `testNonconflictingTransactions()`:\r\n\r\nWhat this test does:\r\n\r\nOpen 10 transactions T1, T2, ..., T10\r\n\r\nT1: SELECT \"kv_key\", \"kv_value\" FROM \"KV\" WHERE \"kv_key\" >= ?1 ORDER BY \"kv_key\" ASC LIMIT 1 [?1 = 00]\r\nT1:  UPSERT INTO \"KV\" (\"kv_key\", \"kv_value\") VALUES (?1, ?2) [?1 = 80, ?2 = 02]\r\nT2: SELECT \"kv_key\", \"kv_value\" FROM \"KV\" WHERE \"kv_key\" >= ?1 ORDER BY \"kv_key\" ASC LIMIT 1 [?1 = 01]\r\nT2: UPSERT INTO \"KV\" (\"kv_key\", \"kv_value\") VALUES (?1, ?2) [?1 = 81, ?2 = 02]\r\nT3: SELECT \"kv_key\", \"kv_value\" FROM \"KV\" WHERE \"kv_key\" >= ?1 ORDER BY \"kv_key\" ASC LIMIT 1 [?1 = 02]\r\n\r\nThe test hangs at this point. The stuck thread is here:\r\n\r\n```\r\n\"pool-1-thread-10\" prio=5 tid=0x00007fbb7e037000 nid=0x6703 runnable [0x000000012259d000]\r\n   java.lang.Thread.State: RUNNABLE\r\n\tat java.net.SocketInputStream.socketRead0(Native Method)\r\n\tat java.net.SocketInputStream.read(SocketInputStream.java:152)\r\n\tat java.net.SocketInputStream.read(SocketInputStream.java:122)\r\n\tat org.postgresql.core.VisibleBufferedInputStream.readMore(VisibleBufferedInputStream.java:143)\r\n\tat org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:112)\r\n\tat org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStream.java:70)\r\n\tat org.postgresql.core.PGStream.ReceiveChar(PGStream.java:283)\r\n\tat org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1799)\r\n\tat org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:200)\r\n\t- locked <0x00000007adec7888> (a org.postgresql.core.v3.QueryExecutorImpl)\r\n\tat org.postgresql.jdbc.PgStatement.execute(PgStatement.java:424)\r\n\tat org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:161)\r\n\tat org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:114)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n\tat java.lang.reflect.Method.invoke(Method.java:606)\r\n\tat org.postgresql.ds.PGPooledConnection$StatementHandler.invoke(PGPooledConnection.java:426)\r\n\tat com.sun.proxy.$Proxy13.executeQuery(Unknown Source)\r\n\tat org.jsimpledb.kv.sql.SQLKVTransaction.query(SQLKVTransaction.java:279)\r\n\tat org.jsimpledb.kv.sql.SQLKVTransaction.queryKVPair(SQLKVTransaction.java:250)\r\n\tat org.jsimpledb.kv.sql.SQLKVTransaction.getAtLeast(SQLKVTransaction.java:100)\r\n\t- locked <0x00000007aded3008> (a org.jsimpledb.kv.cockroach.CockroachKVTransaction)\r\n\tat org.jsimpledb.kv.test.KVDatabaseTest$Reader.call(KVDatabaseTest.java:862)\r\n\tat org.jsimpledb.kv.test.KVDatabaseTest$Reader.call(KVDatabaseTest.java:842)\r\n\tat java.util.concurrent.FutureTask.run(FutureTask.java:262)\r\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)\r\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)\r\n\tat java.lang.Thread.run(Thread.java:744)\r\n```\r\n\r\nTo run these tests yourself:\r\n\r\n1. `git clone git@github.com:archiecobbs/jsimpledb`\r\n1. `cd jsimpledb`\r\n1. `git checkout 89937aa672efd9ab833e28809259d2836bb3e8cb`\r\n1. `mvn install -Dmaven.javadoc.skip=true -Dmaven.test.skip=true`\r\n1. Edit `pom.xml`, and uncomment the `<cockroachURL>` line (edit to suit)\r\n1. `cd jsimpledb-kv-cockroach`\r\n1. `cockroach sql -e 'create database if not exists jsimpledb'`\r\n1. `mvn test`\r\n1. When test hangs, hit `CTRL-\\` to see Java stack trace\r\n"},"comment":{"url":"https://api.github.com/repos/cockroachdb/cockroach/issues/comments/229828519","html_url":"https://github.com/cockroachdb/cockroach/issues/7556#issuecomment-229828519","issue_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/7556","id":229828519,"user":{"login":"archiecobbs","id":545866,"avatar_url":"https://avatars.githubusercontent.com/u/545866?v=3","gravatar_id":"","url":"https://api.github.com/users/archiecobbs","html_url":"https://github.com/archiecobbs","followers_url":"https://api.github.com/users/archiecobbs/followers","following_url":"https://api.github.com/users/archiecobbs/following{/other_user}","gists_url":"https://api.github.com/users/archiecobbs/gists{/gist_id}","starred_url":"https://api.github.com/users/archiecobbs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/archiecobbs/subscriptions","organizations_url":"https://api.github.com/users/archiecobbs/orgs","repos_url":"https://api.github.com/users/archiecobbs/repos","events_url":"https://api.github.com/users/archiecobbs/events{/privacy}","received_events_url":"https://api.github.com/users/archiecobbs/received_events","type":"User","site_admin":false},"created_at":"2016-07-01T00:56:14Z","updated_at":"2016-07-01T00:56:14Z","body":"Thanks for looking into it. We have looped around a bit since the original bug was opened and my apologies for having forgotten how this all started.\r\n\r\nIn all of the other databases, this test results in either a retry exception or a timeout exception, when the blocked thread gives up waiting for the blocking transaction to finish.\r\n\r\nCockroachDB just hangs indefinitely, because there's no way to configure a transaction for such a timeout. This is what the original bug #5924 was about.\r\n\r\nIn the course of testing for #5924, I realized there was actually another test failing, which indicated a separate issue, and so this bug was filed for that problem. But by the time I got around to filing this bug, that second bug had already been fixed.\r\n\r\nSo back to this bug... \r\n\r\nThe behavior makes sense, in that the blocked thread must wait for the blocking transaction. But the larger issue is that CockroachDB, unlike all of the other databases tested with this test, actually makes it impossible to avoid the possibility of an indefinite hang in your program if some other really slow transaction happens to block you.\r\n\r\nThat's why a transaction timeout is needed - _or_, make it impossible to hang indefinitely in some other way, by throwing a retry exception after some built-in internal timeout or whatever. There's no easy way in Java to configure such a timeout on the client side.\r\n\r\nHope this makes sense.\r\n\r\n"}}
{"actor":{"display_login":"archiecobbs"}}