Edits to doAnswer to avoid closing socket before write finishes

When running on Heroku we found that the close often happened before the write finished. This appears to solve that problem.