make sure sockets are closed before closing context (fixes #14)