Skip to content

Commit cc6d136

Browse files
author
virco
committed
clean sockets cache on diff exception
1 parent 7b04c06 commit cc6d136

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

pdiff.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "pfs.h"
4444
#include "pnotifications.h"
4545
#include "pnetlibs.h"
46+
#include "pcache.h"
4647
#include "pbusinessaccount.h"
4748
#include "publiclinks.h"
4849
#include "pcontacts.h"
@@ -2026,8 +2027,10 @@ static void handle_exception(psync_socket **sock, subscribed_ids *ids, char ex){
20262027
else if (ex=='e'){
20272028
binparam diffparams[]={P_STR("id", "ignore")};
20282029
if (!send_command_no_res(*sock, "nop", diffparams) || psync_select_in(&(*sock)->sock, 1, PSYNC_SOCK_TIMEOUT_ON_EXCEPTION*1000)!=0){
2030+
const char *prefixes[]={"API:", "HTTP"};
20292031
debug(D_NOTICE, "reconnecting diff");
20302032
psync_socket_close_bad(*sock);
2033+
psync_cache_clean_starting_with_one_of(prefixes, ARRAY_SIZE(prefixes));
20312034
*sock=get_connected_socket();
20322035
psync_set_status(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_ONLINE);
20332036
psync_syncer_check_delayed_syncs();
@@ -2217,10 +2220,10 @@ static void psync_diff_thread(){
22172220
const binresult *entries;
22182221
uint64_t newdiffid, result;
22192222
psync_socket_t exceptionsock, socks[2];
2220-
subscribed_ids ids = {0,0,0,0};
2221-
int sel,ret = 0;
2223+
subscribed_ids ids = {0, 0, 0, 0};
2224+
int sel, ret=0;
22222225
char ex;
2223-
char *err = NULL;
2226+
char *err=NULL;
22242227
psync_set_status(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_CONNECTING);
22252228
psync_send_status_update();
22262229
restart:

pnetlibs.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ psync_http_socket *psync_http_connect(const char *host, const char *path, uint64
875875
char ch, lch;
876876
char cachekey[256];
877877
usessl=psync_setting_get_bool(_PS(usessl));
878-
cl=snprintf(cachekey, sizeof(cachekey)-1, "HT%d-%s", usessl, host)+1;
878+
cl=snprintf(cachekey, sizeof(cachekey)-1, "HTTP%d-%s", usessl, host)+1;
879879
cachekey[sizeof(cachekey)-1]=0;
880880
sock=(psync_socket *)psync_cache_get(cachekey);
881881
if (!sock){
@@ -1067,7 +1067,7 @@ static void connect_cache_thread(void *ptr){
10671067
else{
10681068
if (sock){
10691069
char cachekey[256];
1070-
snprintf(cachekey, sizeof(cachekey)-1, "HT%d-%s", node->usessl, node->host);
1070+
snprintf(cachekey, sizeof(cachekey)-1, "HTTP%d-%s", node->usessl, node->host);
10711071
cachekey[sizeof(cachekey)-1]=0;
10721072
psync_cache_add(cachekey, sock, 25, (psync_cache_free_callback)psync_socket_close_download, PSYNC_MAX_IDLE_HTTP_CONNS);
10731073
}
@@ -1224,7 +1224,7 @@ psync_http_socket *psync_http_connect_multihost(const binresult *hosts, const ch
12241224
usessl=psync_setting_get_bool(_PS(usessl));
12251225
sock=NULL;
12261226
for (i=0; i<hosts->length; i++){
1227-
cl=snprintf(cachekey, sizeof(cachekey)-1, "HT%d-%s", usessl, hosts->array[i]->str)+1;
1227+
cl=snprintf(cachekey, sizeof(cachekey)-1, "HTTP%d-%s", usessl, hosts->array[i]->str)+1;
12281228
cachekey[sizeof(cachekey)-1]=0;
12291229
sock=(psync_socket *)psync_cache_get(cachekey);
12301230
if (sock){
@@ -1242,7 +1242,7 @@ psync_http_socket *psync_http_connect_multihost(const binresult *hosts, const ch
12421242
if (!sock){
12431243
for (i=0; i<hosts->length; i++)
12441244
if ((sock=connect_cache_wait_for_http_connection(hosts->array[i]->str, usessl))){
1245-
cl=snprintf(cachekey, sizeof(cachekey)-1, "HT%d-%s", usessl, hosts->array[i]->str)+1;
1245+
cl=snprintf(cachekey, sizeof(cachekey)-1, "HTTP%d-%s", usessl, hosts->array[i]->str)+1;
12461246
cachekey[sizeof(cachekey)-1]=0;
12471247
*host=hosts->array[i]->str;
12481248
break;
@@ -1251,7 +1251,7 @@ psync_http_socket *psync_http_connect_multihost(const binresult *hosts, const ch
12511251
for (i=0; i<hosts->length; i++){
12521252
sock=psync_socket_connect(hosts->array[i]->str, usessl?443:80, usessl);
12531253
if (sock){
1254-
cl=snprintf(cachekey, sizeof(cachekey)-1, "HT%d-%s", usessl, hosts->array[i]->str)+1;
1254+
cl=snprintf(cachekey, sizeof(cachekey)-1, "HTTP%d-%s", usessl, hosts->array[i]->str)+1;
12551255
cachekey[sizeof(cachekey)-1]=0;
12561256
*host=hosts->array[i]->str;
12571257
break;
@@ -1284,7 +1284,7 @@ psync_http_socket *psync_http_connect_multihost_from_cache(const binresult *host
12841284
usessl=psync_setting_get_bool(_PS(usessl));
12851285
sock=NULL;
12861286
for (i=0; i<hosts->length; i++){
1287-
cl=snprintf(cachekey, sizeof(cachekey)-1, "HT%d-%s", usessl, hosts->array[i]->str)+1;
1287+
cl=snprintf(cachekey, sizeof(cachekey)-1, "HTTP%d-%s", usessl, hosts->array[i]->str)+1;
12881288
cachekey[sizeof(cachekey)-1]=0;
12891289
sock=(psync_socket *)psync_cache_get(cachekey);
12901290
if (sock){

0 commit comments

Comments
 (0)