While reading from the input in WriteStream, the inmemory driver can deadlock if the reader is from the same instance. To fix this, the write lock is released before reading into a local buffer. The lock is re-acquired to finish the actual write. Signed-off-by: Stephen J Day <stephen.day@docker.com>