Skip to content

Commit 62010d6

Browse files
attilapirosdongjoon-hyun
authored andcommitted
[SPARK-26118][BACKPORT-2.3][WEB UI] Introducing spark.ui.requestHeaderSize for setting HTTP requestHeaderSize
## What changes were proposed in this pull request? Introducing spark.ui.requestHeaderSize for configuring Jetty's HTTP requestHeaderSize. This way long authorization field does not lead to HTTP 413. ## How was this patch tested? Manually with curl (which version must be at least 7.55). With the original default value (8k limit): ```bash $ ./sbin/start-history-server.sh starting org.apache.spark.deploy.history.HistoryServer, logging to /Users/attilapiros/github/spark/logs/spark-attilapiros-org.apache.spark.deploy.history.HistoryServer-1-apiros-MBP.lan.out $ echo -n "X-Custom-Header: " > cookie $ printf 'A%.0s' {1..9500} >> cookie $ curl -H cookie http://458apiros-MBP.lan:18080/ <h1>Bad Message 431</h1><pre>reason: Request Header Fields Too Large</pre> $ tail -1 /Users/attilapiros/github/spark/logs/spark-attilapiros-org.apache.spark.deploy.history.HistoryServer-1-apiros-MBP.lan.out 18/11/19 21:24:28 WARN HttpParser: Header is too large 8193>8192 ``` After: ```bash $ echo spark.ui.requestHeaderSize=10000 > history.properties $ ./sbin/start-history-server.sh --properties-file history.properties starting org.apache.spark.deploy.history.HistoryServer, logging to /Users/attilapiros/github/spark/logs/spark-attilapiros-org.apache.spark.deploy.history.HistoryServer-1-apiros-MBP.lan.out $ curl -H cookie http://458apiros-MBP.lan:18080/ <!DOCTYPE html><html> <head>... <link rel="shortcut icon" href="/static/spark-logo-77x50px-hd.png"></link> <title>History Server</title> </head> <body> ... ``` (cherry picked from commit ab61ddb) Closes #23114 from attilapiros/julianOffByDays-2.3. Authored-by: “attilapiros” <piros.attila.zsolt@gmail.com> Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
1 parent 8b6504e commit 62010d6

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

core/src/main/scala/org/apache/spark/internal/config/package.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,12 @@ package object config {
499499
.stringConf
500500
.createOptional
501501

502+
private[spark] val UI_REQUEST_HEADER_SIZE =
503+
ConfigBuilder("spark.ui.requestHeaderSize")
504+
.doc("Value for HTTP request header size in bytes.")
505+
.bytesConf(ByteUnit.BYTE)
506+
.createWithDefaultString("8k")
507+
502508
private[spark] val EXTRA_LISTENERS = ConfigBuilder("spark.extraListeners")
503509
.doc("Class names of listeners to add to SparkContext during initialization.")
504510
.stringConf

core/src/main/scala/org/apache/spark/ui/JettyUtils.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,15 @@ private[spark] object JettyUtils extends Logging {
355355

356356
(connector, connector.getLocalPort())
357357
}
358+
val httpConfig = new HttpConfiguration()
359+
httpConfig.setRequestHeaderSize(conf.get(UI_REQUEST_HEADER_SIZE).toInt)
358360

359361
// If SSL is configured, create the secure connector first.
360362
val securePort = sslOptions.createJettySslContextFactory().map { factory =>
361363
val securePort = sslOptions.port.getOrElse(if (port > 0) Utils.userPort(port, 400) else 0)
362364
val secureServerName = if (serverName.nonEmpty) s"$serverName (HTTPS)" else serverName
363365
val connectionFactories = AbstractConnectionFactory.getFactories(factory,
364-
new HttpConnectionFactory())
366+
new HttpConnectionFactory(httpConfig))
365367

366368
def sslConnect(currentPort: Int): (ServerConnector, Int) = {
367369
newConnector(connectionFactories, currentPort)
@@ -376,7 +378,7 @@ private[spark] object JettyUtils extends Logging {
376378

377379
// Bind the HTTP port.
378380
def httpConnect(currentPort: Int): (ServerConnector, Int) = {
379-
newConnector(Array(new HttpConnectionFactory()), currentPort)
381+
newConnector(Array(new HttpConnectionFactory(httpConfig)), currentPort)
380382
}
381383

382384
val (httpConnector, httpPort) = Utils.startServiceOnPort[ServerConnector](port, httpConnect,

docs/configuration.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,14 @@ Apart from these, the following properties are also available, and may be useful
909909
How many dead executors the Spark UI and status APIs remember before garbage collecting.
910910
</td>
911911
</tr>
912+
<tr>
913+
<td><code>spark.ui.requestHeaderSize</code></td>
914+
<td>8k</td>
915+
<td>
916+
The maximum allowed size for a HTTP request header, in bytes unless otherwise specified.
917+
This setting applies for the Spark History Server too.
918+
<td>
919+
</tr>
912920
</table>
913921

914922
### Compression and Serialization

0 commit comments

Comments
 (0)