From 518e621d4d7513c830359c4eaaa395a14577d69d Mon Sep 17 00:00:00 2001 From: Patrick Ellul Date: Fri, 11 Mar 2016 11:27:12 +1100 Subject: [PATCH 1/5] In pbc connection, consider a timeout as a BadResource because the fallout is not dealt with. https://github.com/basho/riak-python-client/issues/425 --- riak/transports/pbc/connection.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/riak/transports/pbc/connection.py b/riak/transports/pbc/connection.py index 0bc58232..1b2e7720 100644 --- a/riak/transports/pbc/connection.py +++ b/riak/transports/pbc/connection.py @@ -29,6 +29,7 @@ MSG_CODE_AUTH_RESP ) from riak.util import bytes_to_str, str_to_bytes +from riak.transports.pool import BadResource from six import PY2 if not USE_STDLIB_SSL: from OpenSSL.SSL import Connection @@ -171,7 +172,15 @@ def _ssl_handshake(self): raise SecurityError(e) def _recv_msg(self, expect=None): - self._recv_pkt() + try: + self._recv_pkt() + except socket.timeout, e: + # A timeout can leave the socket in an inconsistent state because + # it might still receive the data later and mix up with a + # subsequent request. + # https://github.com/basho/riak-python-client/issues/425 + raise BadResource(e) + msg_code, = struct.unpack("B", self._inbuf[:1]) if msg_code is MSG_CODE_ERROR_RESP: err = self._parse_msg(msg_code, self._inbuf[1:]) From 4469de4be2ae53c755793fe85fdbb4339bf9437c Mon Sep 17 00:00:00 2001 From: Patrick Ellul Date: Fri, 11 Mar 2016 14:02:27 +1100 Subject: [PATCH 2/5] avoiding merge conflict in import --- riak/transports/pbc/connection.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/riak/transports/pbc/connection.py b/riak/transports/pbc/connection.py index 1b2e7720..d20c096d 100644 --- a/riak/transports/pbc/connection.py +++ b/riak/transports/pbc/connection.py @@ -29,7 +29,7 @@ MSG_CODE_AUTH_RESP ) from riak.util import bytes_to_str, str_to_bytes -from riak.transports.pool import BadResource + from six import PY2 if not USE_STDLIB_SSL: from OpenSSL.SSL import Connection @@ -38,6 +38,8 @@ import ssl from riak.transports.security import configure_ssl_context +from riak.transports.pool import BadResource + class RiakPbcConnection(object): """ From c0255b2f1da78770afb55e5a43547841f3a7c89e Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Wed, 27 Apr 2016 07:12:30 -0700 Subject: [PATCH 3/5] Small fixes, lint --- riak/transports/tcp/connection.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/riak/transports/tcp/connection.py b/riak/transports/tcp/connection.py index ea78a76e..2ac0369f 100644 --- a/riak/transports/tcp/connection.py +++ b/riak/transports/tcp/connection.py @@ -6,6 +6,7 @@ from riak import RiakError from riak.codecs.pbuf import PbufCodec +from riak.transports.pool import BadResource from riak.security import SecurityError, USE_STDLIB_SSL @@ -16,8 +17,6 @@ import ssl from riak.transports.security import configure_ssl_context -from riak.transports.pool import BadResource - class TcpConnection(object): """ @@ -157,7 +156,7 @@ def _ssl_handshake(self): def _recv_msg(self): try: msgbuf = self._recv_pkt() - except socket.timeout, e: + except socket.timeout as e: # A timeout can leave the socket in an inconsistent state because # it might still receive the data later and mix up with a # subsequent request. @@ -168,8 +167,6 @@ def _recv_msg(self): data = mv[1:].tobytes() return (msg_code, data) - - def _recv_pkt(self): # TODO FUTURE re-use buffer msglen_buf = self._recv(4) From bb21de9ff6bb61995383570528cacaa8ac60f36a Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Wed, 27 Apr 2016 07:13:39 -0700 Subject: [PATCH 4/5] Add basic make.ps1 for Windows --- .gitignore | 1 - make.ps1 | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 make.ps1 diff --git a/.gitignore b/.gitignore index e20b3037..3b1e0f43 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,3 @@ riak.egg-info/ .eggs/ #*# *~ -*.ps1 diff --git a/make.ps1 b/make.ps1 new file mode 100644 index 00000000..6d3c4181 --- /dev/null +++ b/make.ps1 @@ -0,0 +1,20 @@ +Set-StrictMode -Version Latest +$ErrorActionPreference = 'Stop' + +$env:RIAK_TEST_HOST = 'riak-test' +$env:RIAK_TEST_PROTOCOL = 'pbc' +$env:RIAK_TEST_PB_PORT = 10017 +$env:RUN_DATATYPES = 1 +$env:RUN_INDEXES = 1 +$env:RUN_POOL = 1 +$env:RUN_YZ = 1 + +flake8 --exclude=riak/pb riak commands.py setup.py version.py +if ($LastExitCode -ne 0) { + throw 'flake8 failed!' +} + +python setup.py test +if ($LastExitCode -ne 0) { + throw 'python tests failed!' +} From 5016352deca12bd3143aea976be54b18c6fe25e8 Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Wed, 27 Apr 2016 07:18:10 -0700 Subject: [PATCH 5/5] add contributor --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ba773034..529b7a20 100644 --- a/README.md +++ b/README.md @@ -178,6 +178,7 @@ Contributors * Mark Phillips * Mathias Meyer * Matt Heitzenroder +* [Matt Lohier](https://github.com/aquam8) * Mikhail Sobolev * Reid Draper * Russell Brown