Skip to content

Commit

Permalink
Merge pull request #102 from pharo-nosql/correct_pool-return-for-broken
Browse files Browse the repository at this point in the history
Add a flag to exception handling to prevent returning a broken connec…
  • Loading branch information
noha authored Jun 9, 2021
2 parents 7eefd95 + c335af1 commit 68e1c19
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions mc/Mongo-Client.package/MongoPool.class/instance/mongoDo..st
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@ accessing
mongoDo: aBlockClosure
"Evaluate the BlockClosure with a Mongo instance. See #next.
For error handling, the specification states that the client MUST clear its connection pool for the server: if one socket is bad, it is likely that all are.
For error handling, the specification states that the client MUST clear its connection pool
for the server: if one socket is bad, it is likely that all are.
Source: https://github.com/mongodb/specifications/blob/573b1f58a129056d651781ad99317b6c656e050e/source/server-discovery-and-monitoring/server-discovery-and-monitoring-summary.rst#id9
"

| mongo result |
[ mongo := self next.
result := [ aBlockClosure value: mongo]
ensure: [
"Use ensurce block here because the block above could have a non local
return which would skip returning the connection. In the error case the
pool will get resetted so this should not have any impact"
self return: mongo ].
^ result ]
| mongo failed |
failed := false.
mongo := self next.
^ [
[ aBlockClosure value: mongo ]
on: NetworkError, MongoWireProtocolError
do: [ :error |
failed := true.
self ensureCloseMongo: mongo.
self resetAll.
error pass ]
error pass ] ]
ensure: [
"Use ensurce block here because aBlockClosure could have a non local
return which would skip returning the connection. So we only return
if the prior exception handler did not mark this as failed"
failed ifFalse: [
self return: mongo ] ]

0 comments on commit 68e1c19

Please sign in to comment.