@@ -313,6 +313,10 @@ var (
313
313
Usage : "Percentage of cache memory allowance to use for trie pruning" ,
314
314
Value : 25 ,
315
315
}
316
+ FDLimitFlag = cli.IntFlag {
317
+ Name : "fdlimit" ,
318
+ Usage : "Raise the open file descriptor resource limit (default = system fd limit)" ,
319
+ }
316
320
// Miner settings
317
321
StakingEnabledFlag = cli.BoolFlag {
318
322
Name : "mine" ,
@@ -816,11 +820,24 @@ func setPrefix(ctx *cli.Context, cfg *node.Config) {
816
820
817
821
// MakeDatabaseHandles raises out the number of allowed file handles per process
818
822
// for XDC and returns half of the allowance to assign to the database.
819
- func MakeDatabaseHandles () int {
823
+ func MakeDatabaseHandles (max int ) int {
820
824
limit , err := fdlimit .Maximum ()
821
825
if err != nil {
822
826
Fatalf ("Failed to retrieve file descriptor allowance: %v" , err )
823
827
}
828
+ switch {
829
+ case max == 0 :
830
+ // User didn't specify a meaningful value, use system limits
831
+ case max < 128 :
832
+ // User specified something unhealthy, just use system defaults
833
+ log .Error ("File descriptor limit invalid (<128)" , "had" , max , "updated" , limit )
834
+ case max > limit :
835
+ // User requested more than the OS allows, notify that we can't allocate it
836
+ log .Warn ("Requested file descriptors denied by OS" , "req" , max , "limit" , limit )
837
+ default :
838
+ // User limit is meaningful and within allowed range, use that
839
+ limit = max
840
+ }
824
841
raised , err := fdlimit .Raise (uint64 (limit ))
825
842
if err != nil {
826
843
Fatalf ("Failed to raise file descriptor allowance: %v" , err )
@@ -1178,7 +1195,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
1178
1195
if ctx .GlobalIsSet (CacheFlag .Name ) || ctx .GlobalIsSet (CacheDatabaseFlag .Name ) {
1179
1196
cfg .DatabaseCache = ctx .GlobalInt (CacheFlag .Name ) * ctx .GlobalInt (CacheDatabaseFlag .Name ) / 100
1180
1197
}
1181
- cfg .DatabaseHandles = MakeDatabaseHandles ()
1198
+ cfg .DatabaseHandles = MakeDatabaseHandles (ctx . GlobalInt ( FDLimitFlag . Name ) )
1182
1199
1183
1200
if gcmode := ctx .GlobalString (GCModeFlag .Name ); gcmode != "full" && gcmode != "archive" {
1184
1201
Fatalf ("--%s must be either 'full' or 'archive'" , GCModeFlag .Name )
@@ -1267,7 +1284,7 @@ func SetupNetwork(ctx *cli.Context) {
1267
1284
func MakeChainDatabase (ctx * cli.Context , stack * node.Node ) ethdb.Database {
1268
1285
var (
1269
1286
cache = ctx .GlobalInt (CacheFlag .Name ) * ctx .GlobalInt (CacheDatabaseFlag .Name ) / 100
1270
- handles = MakeDatabaseHandles ()
1287
+ handles = MakeDatabaseHandles (ctx . GlobalInt ( FDLimitFlag . Name ) )
1271
1288
)
1272
1289
name := "chaindata"
1273
1290
if ctx .GlobalBool (LightModeFlag .Name ) {
0 commit comments