Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not decode file: png: invalid format: not enough pixel data #34

Open
wnd-rgb opened this issue Aug 2, 2024 · 3 comments
Open

Comments

@wnd-rgb
Copy link

wnd-rgb commented Aug 2, 2024

Thanks for this cool program first of all, I'm using it on my 24/7 Earthbound stream at https://twitch.tv/mushguys. Users can issue a command to save a screenshot of the game and send it to the game progress channel. It's very useful. I've had it running for many weeks without issue but it suddenly crashed today. No unusual work load, it is possible that two screenshots were sent close together, and I have the sleep check set to 2 seconds.

panic: could not decode file: png: invalid format: not enough pixel data

goroutine 36 [running]:
github.com/tardisx/discord-auto-upload/image.(*Store).determineFormat(0xc00011bc80)
	/Users/justin/Local Documents/discord-auto-upload/image/image.go:71 +0x11d
github.com/tardisx/discord-auto-upload/image.(*Store).ReadCloser(0xc00011bc80)
	/Users/justin/Local Documents/discord-auto-upload/image/image.go:39 +0x25
github.com/tardisx/discord-auto-upload/upload.(*Upload).processUpload(0xc0002aedc0)
	/Users/justin/Local Documents/discord-auto-upload/upload/upload.go:160 +0x2c7
github.com/tardisx/discord-auto-upload/upload.(*Uploader).Upload(0xc000222020)
	/Users/justin/Local Documents/discord-auto-upload/upload/upload.go:106 +0x9a
main.(*watch).Watch(0xc00020a5a0, 0x2, {0x988450, 0xc000220460})
	/Users/justin/Local Documents/discord-auto-upload/dau.go:108 +0x59
created by main.startWatchers in goroutine 35
	/Users/justin/Local Documents/discord-auto-upload/dau.go:86 +0x208
@tardisx
Copy link
Owner

tardisx commented Aug 2, 2024

Hi @wnd-rgb thanks for the report, and it’s always awesome to see how the app is being used in the wild!

I’d suspect this is an edge case where the file is still being written at the exact time that dau notices it.

Has it only happened once?

Since there’s no reliable way to know that the file has been completely written this is a thorny case. That said it shouldn’t crash completely and I will investigate that.

By what means do you generate the screenshot? Does that process have an option to atomically move or rename the file after writing? That would be a more reliable outcome.

@wnd-rgb
Copy link
Author

wnd-rgb commented Aug 3, 2024

Yes, its only happened the one time, and dau has been running for many weeks now continuously. The screenshots are generated by listening for a command on twitch, parsing it with python and sending a keyboard shortcut to OBS which generates the screenshot as a png in the same folder that dau watches. Perhaps increasing the watch timer would help?

@tardisx
Copy link
Owner

tardisx commented Aug 3, 2024

Increasing the watch timer would make it less statistically likely to happen, but it could still happen.

Ideally, files in the watch dir should be moved in atomically (via a mv command or rename call), then there is no chance they will be partially written. That may be difficult given the way your setup works (you'd have to change OBS to write to a temporary location, and make your python script wait for the file to be written, and then move it to the watch dir).

You'd have to deal with the headaches that dau is currently avoiding :-)

As part of this issue I will at least make it a non-fatal error if a file is half-written and thus can't be decoded. Making it deal with partial files (with some sort of heuristic, to ignore it and try again next loop) is a more complex change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants