|
42 | 42 | from neo4j.packstream import Packer, Unpacker
|
43 | 43 | from neo4j.util import import_best as _import_best
|
44 | 44 | from time import clock
|
45 |
| -from neo4j.config import default_config, INFINITE, TRUST_ON_FIRST_USE |
| 45 | +from neo4j.config import get_config, INFINITE, TRUST_ON_FIRST_USE |
46 | 46 |
|
47 | 47 | ChunkedInputBuffer = _import_best("neo4j.bolt._io", "neo4j.bolt.io").ChunkedInputBuffer
|
48 | 48 | ChunkedOutputBuffer = _import_best("neo4j.bolt._io", "neo4j.bolt.io").ChunkedOutputBuffer
|
@@ -170,16 +170,19 @@ def __init__(self, address, sock, error_handler, **config):
|
170 | 170 | self.socket = sock
|
171 | 171 | self.error_handler = error_handler
|
172 | 172 | self.server = ServerInfo(SocketAddress.from_socket(sock))
|
173 |
| - self.input_buffer = ChunkedInputBuffer() |
174 |
| - self.output_buffer = ChunkedOutputBuffer() |
| 173 | + self.input_buffer = ChunkedInputBuffer(get_config(config, "input_buffer_capacity")) |
| 174 | + self.output_buffer = ChunkedOutputBuffer( |
| 175 | + get_config(config, "output_buffer_capacity"), |
| 176 | + get_config(config, "output_buffer_max_chunk_size") |
| 177 | + ) |
175 | 178 | self.packer = Packer(self.output_buffer)
|
176 | 179 | self.unpacker = Unpacker()
|
177 | 180 | self.responses = deque()
|
178 |
| - self._max_connection_lifetime = config.get("max_connection_lifetime", default_config["max_connection_lifetime"]) |
| 181 | + self._max_connection_lifetime = get_config(config, "max_connection_lifetime") |
179 | 182 | self._creation_timestamp = clock()
|
180 | 183 |
|
181 | 184 | # Determine the user agent and ensure it is a Unicode value
|
182 |
| - user_agent = config.get("user_agent", default_config["user_agent"]) |
| 185 | + user_agent = get_config(config, "user_agent") |
183 | 186 | if isinstance(user_agent, bytes):
|
184 | 187 | user_agent = user_agent.decode("UTF-8")
|
185 | 188 | self.user_agent = user_agent
|
@@ -328,14 +331,20 @@ def _fetch(self):
|
328 | 331 | return len(details), 1
|
329 | 332 |
|
330 | 333 | def _receive(self):
|
| 334 | + err_msg = None |
331 | 335 | try:
|
332 | 336 | received = self.input_buffer.receive_message(self.socket, 8192)
|
| 337 | + except BufferError: |
| 338 | + err_msg = "Overflow. Increase \"input_buffer_capacity\" for connection {!r}" |
| 339 | + received = False |
333 | 340 | except SocketError:
|
334 | 341 | received = False
|
335 | 342 | if not received:
|
336 | 343 | self._defunct = True
|
337 | 344 | self.close()
|
338 |
| - raise self.Error("Failed to read from defunct connection {!r}".format(self.server.address)) |
| 345 | + if not err_msg: |
| 346 | + err_msg = "Failed to read from defunct connection {!r}" |
| 347 | + raise self.Error(err_msg.format(self.server.address)) |
339 | 348 |
|
340 | 349 | def _unpack(self):
|
341 | 350 | unpacker = self.unpacker
|
@@ -405,8 +414,8 @@ def __init__(self, connector, connection_error_handler, **config):
|
405 | 414 | self.connections = {}
|
406 | 415 | self.lock = RLock()
|
407 | 416 | self.cond = Condition(self.lock)
|
408 |
| - self._max_connection_pool_size = config.get("max_connection_pool_size", default_config["max_connection_pool_size"]) |
409 |
| - self._connection_acquisition_timeout = config.get("connection_acquisition_timeout", default_config["connection_acquisition_timeout"]) |
| 417 | + self._max_connection_pool_size = get_config(config, "max_connection_pool_size") |
| 418 | + self._connection_acquisition_timeout = get_config(config, "connection_acquisition_timeout") |
410 | 419 |
|
411 | 420 | def __enter__(self):
|
412 | 421 | return self
|
@@ -544,10 +553,10 @@ def connect(address, ssl_context=None, error_handler=None, **config):
|
544 | 553 | else:
|
545 | 554 | raise ValueError("Unsupported address {!r}".format(address))
|
546 | 555 | t = s.gettimeout()
|
547 |
| - s.settimeout(config.get("connection_timeout", default_config["connection_timeout"])) |
| 556 | + s.settimeout(get_config(config, "connection_timeout")) |
548 | 557 | s.connect(address)
|
549 | 558 | s.settimeout(t)
|
550 |
| - s.setsockopt(SOL_SOCKET, SO_KEEPALIVE, 1 if config.get("keep_alive", default_config["keep_alive"]) else 0) |
| 559 | + s.setsockopt(SOL_SOCKET, SO_KEEPALIVE, 1 if get_config(config, "keep_alive") else 0) |
551 | 560 | except SocketTimeout:
|
552 | 561 | if s:
|
553 | 562 | try:
|
@@ -586,7 +595,7 @@ def connect(address, ssl_context=None, error_handler=None, **config):
|
586 | 595 | s.close()
|
587 | 596 | raise ProtocolError("When using a secure socket, the server should always "
|
588 | 597 | "provide a certificate")
|
589 |
| - trust = config.get("trust", default_config["trust"]) |
| 598 | + trust = get_config(config, "trust") |
590 | 599 | if trust == TRUST_ON_FIRST_USE:
|
591 | 600 | from neo4j.bolt.cert import PersonalCertificateStore
|
592 | 601 | store = PersonalCertificateStore()
|
|
0 commit comments