changeset 16499:db1f217e53b3

lib-dict: Error handling fixes to asynchronous transactions.
author Timo Sirainen <tss@iki.fi>
date Wed, 12 Jun 2013 22:03:07 +0300
parents db5d4c5164b3
children c903fbcbf5d2
files src/lib-dict/dict-client.c
diffstat 1 files changed, 6 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-dict/dict-client.c	Wed Jun 12 21:41:09 2013 +0300
+++ b/src/lib-dict/dict-client.c	Wed Jun 12 22:03:07 2013 +0300
@@ -73,6 +73,7 @@
 	unsigned int failed:1;
 	unsigned int sent_begin:1;
 	unsigned int async:1;
+	unsigned int committed:1;
 };
 
 static int client_dict_connect(struct client_dict *dict);
@@ -262,6 +263,9 @@
 		i_error("dict-client: Unknown transaction id %u", id);
 		return;
 	}
+	ctx->failed = TRUE;
+	if (!ctx->committed)
+		return;
 
 	/* the callback may call the dict code again, so remove this
 	   transaction before calling it */
@@ -402,8 +406,6 @@
 {
 	const char *query;
 
-	i_assert(dict->fd == -1);
-
 	if (dict->last_failed_connect == ioloop_time) {
 		/* Try again later */
 		return -1;
@@ -427,8 +429,6 @@
 
 	dict->input = i_stream_create_fd(dict->fd, (size_t)-1, FALSE);
 	dict->output = o_stream_create_fd(dict->fd, 4096, FALSE);
-	dict->transaction_id_counter = 0;
-	dict->async_commits = 0;
 
 	query = t_strdup_printf("%c%u\t%u\t%d\t%s\t%s\n",
 				DICT_PROTOCOL_CMD_HELLO,
@@ -518,6 +518,7 @@
 	struct client_dict *dict = (struct client_dict *)_dict;
 
         client_dict_disconnect(dict);
+	i_assert(dict->transactions == NULL);
 	pool_unref(&dict->pool);
 }
 
@@ -706,6 +707,7 @@
 	struct client_dict *dict = (struct client_dict *)_ctx->dict;
 	int ret = ctx->failed ? -1 : 1;
 
+	ctx->committed = TRUE;
 	if (ctx->sent_begin && !ctx->failed) T_BEGIN {
 		const char *query, *line;