client_python icon indicating copy to clipboard operation
client_python copied to clipboard

`write_to_textfile` leaves back temp files on errors

Open calestyo opened this issue 1 year ago • 2 comments

Hey.

A simple:

prometheus_client.write_to_textfile("", registry=registry)

which causes an exception:

Traceback (most recent call last):
  File "/home/calestyo/prj/prometheus-smart-array-collector/src/./smart-array.py", line 1185, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/calestyo/prj/prometheus-smart-array-collector/src/./smart-array.py", line 1176, in main
    prometheus_client.write_to_textfile("", registry=registry)
  File "/usr/lib/python3/dist-packages/prometheus_client/exposition.py", line 363, in write_to_textfile
    os.rename(tmppath, path)
FileNotFoundError: [Errno 2] No such file or directory: '.969277.139657657282624' -> ''

shows that the module doesn't properly clean up it's temp files on errors, as that file is left over afterwards.

Cheers, Chris.

calestyo avatar Jul 04 '24 23:07 calestyo

Seems reasonable to avoid leaving around tons of temporary files, though they will be cleaned up eventually. I'd be happy to accept a PR.

csmarchbanks avatar Jul 11 '24 19:07 csmarchbanks

PTAL #1066 @calestyo @csmarchbanks

ethanschen avatar Oct 16 '24 16:10 ethanschen