The current implementation of sendRequest do not ensure that the previous one has been fulfilled before sending a new request.
If two request Req1 and Req2 are sent before any response is received, this can cause a race condition where the response of Req2 will be written to Req1 houseId
BaseChainlinkFunctionsOracle::sendRequest uses the Chainlink Functions to retrieve house prices through API call that are executed by a network of generalized oracles.
When a request is sent on-chain, an event is emitted, which is then caught by the Chainlink network that will execute the request, and return the requested value by calling the BaseChainlinkFunctionsOracle::fulfillRequest function.
During sendRequest, an internal function _beforeFulfill is called:
And here's what is done in _beforeFulfill:
The function sets the lastHouseId to the same value that the one that is encoded in the request.
Then, when Chainlink returns the response by calling fulfillRequest, the internal function _processResponse is called and finally set the price of the lastHouseId
Now, if 2 requests are sent, the first one will be for houseId1 and the second for houseId2.
Which means that lastHouseId will be set to houseId2.
But when the fulfillment will be returned for the first request (which is houseId1) , it will be written as the price for houseId2
As there is no insurance in which order the requests will be processed by the Chainlink network, there is risk of race condition when multiple requests are sent.
If this occurs, the wrong price will be registered for a houseId.
There are two possible ways to manage this:
Prevent new requests to be sent until the previous one has been fulfilled (e.g. by using a lock variable)
In _processResponse, rather than relying on the internal state variable lastHouseId, make the response also return the requested houseId, and use that value to update the price.
Example for method 2:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.