Index: loudmouth/lm-connection.c
===================================================================
--- loudmouth/lm-connection.c	(revision 4057)
+++ loudmouth/lm-connection.c	(revision 4058)
@@ -354,7 +354,7 @@
 
 	/* Need some way to report error/success */
 	if (connection->cancel_open) {
-		return FALSE;
+		goto failure;
 	}
 	
 	connection->fd = connect_data->fd;
@@ -382,7 +382,7 @@
 			close (connection->fd);
 		
 			connection_do_close (connection);
-			return FALSE;
+			goto failure;
 		}
 	}
 	
@@ -419,7 +419,7 @@
 			      "<?xml version='1.0' encoding='UTF-8'?>", -1,
 			      NULL)) {
 		connection_do_close (connection);
-		return FALSE;
+		goto failure;
 	}
 
 	if (connection->jid != NULL && (ch = strchr (connection->jid, '@')) != NULL) {
@@ -440,12 +440,21 @@
 	if (!lm_connection_send (connection, m, NULL)) {
 		lm_message_unref (m);
 		connection_do_close (connection);
-		return FALSE;
+		goto failure;
 	}
 		
 	lm_message_unref (m);
 
 	/* Success */
+	return TRUE;
+
+failure:
+	if (connection->open_cb && connection->open_cb->func) {
+		LmCallback *cb = connection->open_cb;
+		
+		(* ((LmResultFunction) cb->func)) (connection, FALSE,
+						   cb->user_data);
+	}
 	return FALSE;
 }
 
@@ -815,13 +824,18 @@
 	connection_stop_keep_alive (connection);
 
 	if (connection->io_channel) {
-		g_source_destroy (g_main_context_find_source_by_id (
-			connection->context, connection->io_watch_in));
-		g_source_destroy (g_main_context_find_source_by_id (
-			connection->context, connection->io_watch_err));
-		g_source_destroy (g_main_context_find_source_by_id (
-			connection->context, connection->io_watch_hup));
-
+		if (connection->io_watch_in) {
+	       		g_source_destroy (g_main_context_find_source_by_id (
+				connection->context, connection->io_watch_in));
+		}
+		if (connection->io_watch_err) {
+			g_source_destroy (g_main_context_find_source_by_id (
+				connection->context, connection->io_watch_err));
+		}
+		if (connection->io_watch_hup) {
+			g_source_destroy (g_main_context_find_source_by_id (
+				connection->context, connection->io_watch_hup));
+		}
 		if (connection->io_watch_out != 0) {
 			g_source_destroy (g_main_context_find_source_by_id (
 				connection->context, connection->io_watch_out));
Index: loudmouth/lm-proxy.c
===================================================================
--- loudmouth/lm-proxy.c	(revision 4057)
+++ loudmouth/lm-proxy.c	(revision 4058)
@@ -142,7 +142,7 @@
 	g_return_val_if_fail (proxy != NULL, FALSE);
 
 	if (lm_connection_is_open (connection)) {
-		return FALSE;
+		goto failed;
 	}
 
 	switch (lm_proxy_get_type (proxy)) {
@@ -161,6 +161,11 @@
 	}
 
 	return FALSE;
+
+failed:
+	_lm_connection_failed ((LmConnectData *) data);
+
+	return FALSE;
 }
 
 gboolean
