Ensure that connection list is in sync in ImApp and RemoteImService

fixes #2221
Prevent race condition when removing connection

fixes #2221
Merge pull request #339 from devrandom/bug_conn_npe

Ensure that connection list is in sync in ImApp and RemoteImService