contribsys / faktory

Language-agnostic persistent background job server
https://contribsys.com/faktory/
Other
5.76k stars 230 forks source link

Read multiple configs safely #302

Closed jbielick closed 4 years ago

jbielick commented 4 years ago

Purpose

Fixes #191

Approach

Concatenate byte slices of each config file and unmarshal at the end of reading all configs.

Issue

Subsequent unmarshal was overwriting keys in the cumulative hash of configuration.

Considerations

Appending bytes from each file and unmarshaling at the end prevents this overwriting from occurring at the cost of not knowing which config has an error if the cumulative contents do not parse correctly.

mperham commented 4 years ago

Well done, can’t believe I did t think of this approach.

jbielick commented 4 years ago

@mperham one note: I knowingly didn't address config files that are missing a trailing newline. To protect against that I could add one line:

fileBytes = append(fileBytes, "\n"...)

Would you like a PR for that line?

mperham commented 4 years ago

Yeah we’ll want that.