1
1
# Async timeout
2
2
3
- The ` graphql.servlet.async- timeout ` property enables you to define a request level timeout to be enforced. This can help
3
+ The ` graphql.servlet.async. timeout ` property enables you to define a request level timeout to be enforced. This can help
4
4
in preventing DDoS attacks. This is only available when running the application in ` servlet ` mode. The value is the
5
5
timeout in milliseconds that should be enforced. If the GraphQL request has not finished within that timeout a GraphQL
6
6
error will be returned:
@@ -30,12 +30,9 @@ In this example the timeout has been configured at 500 milliseconds in
30
30
[ application.yml] ( src/main/resources/application.yml ) .
31
31
32
32
``` yaml
33
- graphql.servlet.async- timeout : 500
33
+ graphql.servlet.async. timeout : 500
34
34
` ` `
35
35
36
- Note that the property ` graphql.servlet.async-mode-enabled` has not been set to `true` here, because that's it's enabled
37
- by default already.
38
-
39
36
## GraphQL execution cancellation
40
37
41
38
The [Query](src/main/java/com/graphql/sample/boot/Query.java) class shows two examples of queries that will take 3000
@@ -59,11 +56,11 @@ query {
59
56
60
57
Either one will stop processing after 500ms because of the configured timeout.
61
58
62
- The main difference between the two methods in the `Query` class however is the ability to also cancel the execution of
59
+ ~~ The main difference between the two methods in the ` Query ` class however is the ability to also cancel the execution of
63
60
the GraphQL request. Ideally the GraphQL execution is cancelled as well, because otherwise that request is still taking
64
61
up resources and Thread(s) even though the HTTP request has stopped. An attacker could repeatedly call that particular
65
62
GraphQL query which now returns fast, and that would spawn a new Thread with long running execution within the
66
- application itself. That could ultimately lead to an application that crashes because it runs out of memory for example.
63
+ application itself. That could ultimately lead to an application that crashes because it runs out of memory for example.~~
67
64
68
65
To make the GraphQL requests themselves cancellable you only have to remember to always return a ` CompletableFuture `
69
66
instead of the value directly. The ` Query.getHello() ` method is a simple example of a cancellable GraphQL request.
0 commit comments