Browse code

presence: be more resilient doing clean up of presentity values

previously if an error was found we were bailing out and the value
was kept so at next round the value will be there and no more values
where removed

Victor Seva authored on 29/06/2022 07:03:14 • Victor Seva committed on 29/06/2022 13:45:09
Showing 1 changed files
... ...
@@ -69,6 +69,7 @@ void ps_presentity_db_timer_clean(unsigned int ticks, void *param)
69 69
 	int n_db_cols = 0, n_result_cols = 0;
70 70
 	int event_col, etag_col, user_col, domain_col;
71 71
 	int i = 0, num_watchers = 0;
72
+	pres_ev_t fake;
72 73
 	presentity_t pres;
73 74
 	str uri = {0, 0}, event, *rules_doc = NULL;
74 75
 	static str query_str;
... ...
@@ -121,6 +122,7 @@ void ps_presentity_db_timer_clean(unsigned int ticks, void *param)
121 122
 		rows = RES_ROWS(result);
122 123
 
123 124
 		for(i = 0; i < RES_ROW_N(result); i++) {
125
+			num_watchers = 0;
124 126
 			values = ROW_VALUES(&rows[i]);
125 127
 			memset(&pres, 0, sizeof(presentity_t));
126 128
 
... ...
@@ -134,28 +136,33 @@ void ps_presentity_db_timer_clean(unsigned int ticks, void *param)
134 136
 			event.len = strlen(event.s);
135 137
 			pres.event = contains_event(&event, NULL);
136 138
 			if(pres.event == NULL || pres.event->evp == NULL) {
137
-				LM_ERR("event not found\n");
138
-				goto error;
139
+				LM_ERR("event[%.*s] not found\n", STR_FMT(&event));
140
+				memset(&fake, 0, sizeof(pres_ev_t));
141
+				fake.name = event;
142
+				pres.event = &fake;
143
+				goto simple_error;
139 144
 			}
140 145
 
141 146
 			if(uandd_to_uri(pres.user, pres.domain, &uri) < 0) {
142
-				LM_ERR("constructing uri\n");
143
-				goto error;
147
+				LM_ERR("constructing uri from [user]=%.*s  [domain]=%.*s\n",
148
+					STR_FMT(&pres.user), STR_FMT(&pres.domain));
149
+				goto simple_error;
144 150
 			}
145 151
 
146 152
 			/* delete from hash table */
147 153
 			if(publ_cache_mode==PS_PCACHE_HYBRID
148 154
 					&& delete_phtable(&uri, pres.event->evp->type) < 0) {
149
-				LM_ERR("deleting from presentity hash table\n");
150
-				goto error;
155
+				LM_ERR("deleting uri[%.*s] event[%.*s] from presentity hash table\n",
156
+					STR_FMT(&uri), STR_FMT(&event));
157
+				goto simple_error;
151 158
 			}
152 159
 
153
-			LM_DBG("found expired publish for [user]=%.*s  [domanin]=%.*s\n",
160
+			LM_DBG("found expired publish for [user]=%.*s  [domain]=%.*s\n",
154 161
 					pres.user.len, pres.user.s, pres.domain.len, pres.domain.s);
155 162
 
156 163
 			if(pres_force_delete == 1) {
157 164
 				if(delete_presentity(&pres, NULL) < 0) {
158
-					LM_ERR("Deleting presentity\n");
165
+					LM_ERR("Deleting presentity uri[%.*s]\n", STR_FMT(&uri));
159 166
 					goto error;
160 167
 				}
161 168
 			} else if(pres_notifier_processes > 0) {
... ...
@@ -171,7 +178,7 @@ void ps_presentity_db_timer_clean(unsigned int ticks, void *param)
171 178
 						if(pa_dbf.abort_transaction(pa_db) < 0)
172 179
 							LM_ERR("in abort_transaction\n");
173 180
 					}
174
-					goto error;
181
+					goto next;
175 182
 				}
176 183
 
177 184
 				if(num_watchers > 0) {
... ...
@@ -181,12 +188,12 @@ void ps_presentity_db_timer_clean(unsigned int ticks, void *param)
181 188
 							if(pa_dbf.abort_transaction(pa_db) < 0)
182 189
 								LM_ERR("in abort_transaction\n");
183 190
 						}
184
-						goto error;
191
+						goto next;
185 192
 					}
186 193
 				} else {
187 194
 					if(delete_presentity(&pres, NULL) < 0) {
188
-						LM_ERR("Deleting presentity\n");
189
-						goto error;
195
+						LM_ERR("Deleting presentity uri[%.*s]\n", STR_FMT(&uri));
196
+						goto next;
190 197
 					}
191 198
 				}
192 199
 				if(pa_dbf.end_transaction) {
... ...
@@ -201,22 +208,30 @@ void ps_presentity_db_timer_clean(unsigned int ticks, void *param)
201 208
 								   &pres.user, &pres.domain, &rules_doc)
202 209
 								   < 0) {
203 210
 					LM_ERR("getting rules doc\n");
204
-					goto error;
211
+					goto simple_error;
205 212
 				}
206 213
 				if(publ_notify(&pres, uri, NULL, &pres.etag, rules_doc) < 0) {
207 214
 					LM_ERR("sending Notify request\n");
208
-					goto error;
209
-				}
210
-				if(rules_doc) {
211
-					if(rules_doc->s)
212
-						pkg_free(rules_doc->s);
213
-					pkg_free(rules_doc);
214
-					rules_doc = NULL;
215
+					goto simple_error;
215 216
 				}
216 217
 			}
217 218
 
218
-			pkg_free(uri.s);
219
-			uri.s = NULL;
219
+simple_error:
220
+			if(num_watchers == 0 && delete_presentity(&pres, NULL) < 0) {
221
+				LM_ERR("Deleting presentity\n");
222
+			}
223
+next:
224
+			if(uri.s) {
225
+				pkg_free(uri.s);
226
+				uri.s = NULL;
227
+			}
228
+			if(rules_doc) {
229
+				if(rules_doc->s) {
230
+					pkg_free(rules_doc->s);
231
+				}
232
+				pkg_free(rules_doc);
233
+				rules_doc = NULL;
234
+			}
220 235
 		}
221 236
 	} while(db_fetch_next(&pa_dbf, pres_fetch_rows, pa_db, &result) == 1
222 237
 			&& RES_ROW_N(result) > 0);