confluentinc / kafka-rest

Confluent REST Proxy for Kafka
https://docs.confluent.io/current/kafka-rest/docs/index.html
Other
47 stars 647 forks source link

Publishing a message to a non-existent topic without auto topic creation returns GATEWAY_TIMEOUT #231

Open fangliuwh opened 8 years ago

fangliuwh commented 8 years ago

In my setup of the kafka restproxy, the auto topic creation is switched off; And topic 'test' is not manually created either. Sending the following message gets gateway timeout. I think there are two issues with it: (1) the response code GatewayTimeout is wrong. Would BadRequest be better? (2) it takes long time before we get the gateway timeout (kind of expected in case of gateway timeout), but it should take much less time if we change it to return other error code.

curl -X POST -H "Content-Type: application/vnd.kafka.binary.v1+json" --data "{\"records\":[{\"value\":\"S2Fma2E=\"}]}" "http://localhost:8082/topics/test" -v

jsmaupin commented 7 years ago

Would it be possible to return 404 Not Found here given that the resource does not exist?

ewencp commented 7 years ago

Unfortunately it's difficult to satisfy the needs of both clusters w/ auto topic creation and those without. Returning a 404 immediately might be feasible, though we'd then have to invalidate the cached metadata immediately so that any subsequent produce request wouldn't also immediately fail if auto topic creation was enabled. Also, to make it work with auto topic creation, we need to actually try to produce the data, but the reason for the timeout is that when we try to produce it the failure doesn't occur until after this timeout.

If you would prefer getting something other than a timeout error, I'd recommend adjusting the max.block.ms setting in your REST proxy configuration file. It defaults to 60s which is longer than the timeout imposed for each request. If you reduce it to less than the 30s timeout, if a topic isn't available after the specified amount of time you'll get a 500 error with error coded 50003 indicating a timeout. Your app could then decide what to do with that (retry if you expect auto topic creation to be enabled, fail/log an error if you don't).