@@ -313,6 +313,10 @@ var (
313313 Usage : "Percentage of cache memory allowance to use for trie pruning" ,
314314 Value : 25 ,
315315 }
316+ FDLimitFlag = cli.IntFlag {
317+ Name : "fdlimit" ,
318+ Usage : "Raise the open file descriptor resource limit (default = system fd limit)" ,
319+ }
316320 // Miner settings
317321 StakingEnabledFlag = cli.BoolFlag {
318322 Name : "mine" ,
@@ -816,11 +820,24 @@ func setPrefix(ctx *cli.Context, cfg *node.Config) {
816820
817821// MakeDatabaseHandles raises out the number of allowed file handles per process
818822// for XDC and returns half of the allowance to assign to the database.
819- func MakeDatabaseHandles () int {
823+ func MakeDatabaseHandles (max int ) int {
820824 limit , err := fdlimit .Maximum ()
821825 if err != nil {
822826 Fatalf ("Failed to retrieve file descriptor allowance: %v" , err )
823827 }
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+ }
824841 raised , err := fdlimit .Raise (uint64 (limit ))
825842 if err != nil {
826843 Fatalf ("Failed to raise file descriptor allowance: %v" , err )
@@ -1178,7 +1195,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
11781195 if ctx .GlobalIsSet (CacheFlag .Name ) || ctx .GlobalIsSet (CacheDatabaseFlag .Name ) {
11791196 cfg .DatabaseCache = ctx .GlobalInt (CacheFlag .Name ) * ctx .GlobalInt (CacheDatabaseFlag .Name ) / 100
11801197 }
1181- cfg .DatabaseHandles = MakeDatabaseHandles ()
1198+ cfg .DatabaseHandles = MakeDatabaseHandles (ctx . GlobalInt ( FDLimitFlag . Name ) )
11821199
11831200 if gcmode := ctx .GlobalString (GCModeFlag .Name ); gcmode != "full" && gcmode != "archive" {
11841201 Fatalf ("--%s must be either 'full' or 'archive'" , GCModeFlag .Name )
@@ -1267,7 +1284,7 @@ func SetupNetwork(ctx *cli.Context) {
12671284func MakeChainDatabase (ctx * cli.Context , stack * node.Node ) ethdb.Database {
12681285 var (
12691286 cache = ctx .GlobalInt (CacheFlag .Name ) * ctx .GlobalInt (CacheDatabaseFlag .Name ) / 100
1270- handles = MakeDatabaseHandles ()
1287+ handles = MakeDatabaseHandles (ctx . GlobalInt ( FDLimitFlag . Name ) )
12711288 )
12721289 name := "chaindata"
12731290 if ctx .GlobalBool (LightModeFlag .Name ) {
0 commit comments