Closing connection properly in MessagingService.