@@ -20,8 +20,13 @@ export const MIN_LIFETIME = 30 * 1000;
20
20
export const MIN_HEARTBEAT = 5000 ;
21
21
export const MAX_HEARTBEAT = 120000 ;
22
22
export const MAX_CHANGEFEEDS_PER_ACCOUNT = parseInt (
23
- process . env . COCALC_MAX_CHANGEFEEDS_PER_ACCOUNT ?? "150 " ,
23
+ process . env . MAX_CHANGEFEEDS_PER_ACCOUNT ?? "100 " ,
24
24
) ;
25
+
26
+ export const MAX_CHANGEFEEDS_PER_SERVER = parseInt (
27
+ process . env . MAX_CHANGEFEEDS_PER_SERVER ?? "5000" ,
28
+ ) ;
29
+
25
30
export const LAST_CHUNK = "last-chunk" ;
26
31
27
32
const logger = getLogger ( "changefeed:server" ) ;
@@ -52,6 +57,16 @@ let terminated = false;
52
57
let sub : Subscription | null = null ;
53
58
export async function init ( db ) {
54
59
logger . debug ( "starting changefeed server" ) ;
60
+ logger . debug ( {
61
+ DEFAULT_LIFETIME ,
62
+ MAX_LIFETIME ,
63
+ MIN_LIFETIME ,
64
+ MIN_HEARTBEAT ,
65
+ MAX_HEARTBEAT ,
66
+ MAX_CHANGEFEEDS_PER_ACCOUNT ,
67
+ MAX_CHANGEFEEDS_PER_SERVER ,
68
+ SUBJECT ,
69
+ } ) ;
55
70
changefeedMainLoop ( db ) ;
56
71
renewMainLoop ( ) ;
57
72
}
@@ -230,6 +245,18 @@ async function handleMessage(mesg, db) {
230
245
) ;
231
246
return ;
232
247
}
248
+ if ( numChangefeeds >= MAX_CHANGEFEEDS_PER_SERVER ) {
249
+ logger . debug ( "numChangefeeds >= MAX_CHANGEFEEDS_PER_SERVER" , {
250
+ numChangefeeds,
251
+ MAX_CHANGEFEEDS_PER_SERVER ,
252
+ } ) ;
253
+ // this will just cause the client to make another attempt, hopefully
254
+ // to another server
255
+ respond (
256
+ `There is a limit of ${ MAX_CHANGEFEEDS_PER_SERVER } changefeeds per server` ,
257
+ ) ;
258
+ return ;
259
+ }
233
260
234
261
let { heartbeat } = request ;
235
262
const lifetime = getLifetime ( request ) ;
0 commit comments