replace writer.Close() with write.close()

1. call transactionCleanup() in writer.close()