In the raw_measurement calls and I think there is an opportunity for optimizing it a bit.
Specifically I am seeing that https://github.com/ooni/backend/blob/master/ooniapi/services/oonimeasurements/src/oonimeasurements/routers/v1/measurements.py#L77 doesn't explicitly close the file descriptors operating on the files so in theory there could be some FD leak happening and/or lead to them not getting cleaned up by the garbage collector deterministically.
This task is about refactoring it using contextlib import closing for the urlopen fd and making use of the context manager for GZip too.
In the
raw_measurementcalls and I think there is an opportunity for optimizing it a bit.Specifically I am seeing that https://github.com/ooni/backend/blob/master/ooniapi/services/oonimeasurements/src/oonimeasurements/routers/v1/measurements.py#L77 doesn't explicitly close the file descriptors operating on the files so in theory there could be some FD leak happening and/or lead to them not getting cleaned up by the garbage collector deterministically.
This task is about refactoring it using
contextlib import closingfor theurlopenfd and making use of the context manager for GZip too.