Move de/serialization to ruby for easier error detection.

Closes open transactions if de/serialization fails for any reason,
avoiding the object to be in a potentially confused state.

Thanks to Michael Granger (ged@faeriemud.org) for the heads up and test case.

FossilOrigin-Name: e6e52675510533da8a26b0e2f0b2f73505a3b4ee0c94b123c37089489ed7745a
This commit is contained in:
Mahlon E. Smith 2021-10-06 20:43:13 +00:00
parent 6cc96d8fae
commit 25655d0554
4 changed files with 56 additions and 29 deletions

View file

@ -364,6 +364,34 @@ class MDBX::Database
protected
#########
### Safely serialize a value, closing any open transaction and re-raising
### if necessary.
###
def serialize( val )
return val unless self.serializer
return self.serializer.call( val )
rescue => err
self.close_transaction( false )
raise err
end
### Safely deserialize a value, closing any open transaction and re-raising
### if necessary.
###
def deserialize( val )
return val unless self.deserializer
return self.deserializer.call( val )
rescue => err
self.close_transaction( false )
raise err
end
### Yield and return the block, opening a snapshot first if
### there isn't already a transaction in progress. Closes
### the snapshot if this method opened it.