Skip to content

FixedSizePool.bind unconditionally requests for the same session count on every loop iteration, hence could end up creating much more sessions than necessary; should decrement them per call #1226

@odeke-em

Description

@odeke-em

Found while I was writing tests for PR #1207 that this code in each iteration requests for the original number of sessions in every loop iteration

while not self._sessions.full():
resp = api.batch_create_sessions(
request=request,
metadata=metadata,
)
for session_pb in resp.session:
session = self._new_session()
session._session_id = session_pb.name.split("/")[-1]
self._sessions.put(session)

and the basic tests inside tests/unit/test_pool.py when ran, the loop runs twice but each time the count is kept the exact same per
resp = api.batch_create_sessions(
request=request,
metadata=metadata,
)

You can add prints and you'll see that the loop runs twice but each time 2 sessions are returned but yet 4 sessions were requested

Suggestion

The correct remedy for this is that per iteration, the current size of the filled in queue must be considered in relation to filling it up request.session_count = requested_session_count - self._sessions.qsize()

Metadata

Metadata

Assignees

Labels

api: spannerIssues related to the googleapis/python-spanner API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions