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