Explicitly close the writer, if the reader raises an error

If the reader raised an error, the writer did not get explicitly
closed. Hence, writers did not receive a GeneratorExit and could not
properly clean up after themselves. Due to this lack of GeneratorExit,
the mysql writer would not close the writing thread and hence the
consumer would not exit if the reader raised an error. Hence, we now
explicitly close the writer if the read/write loop exits for whatever
reason. Thereby, the mysql writer can properly close the writing
thread, if the reader bails out.

Change-Id: I630c3861fdd1297484342c5d9b9e9aa61ec04ef3