apache/gravitino

[Improvement] Handle /configs servlet write failures with explicit HTTP 500

已關閉

#10,268 建立於 2026年3月6日

 (1 則留言) (0 個反應) (0 位負責人)Java (887 個分叉)auto 404
good first issueimprovement

倉庫指標

星標
 (3,058 顆星)
PR 合併指標
 (平均合併 6天 6小時) (30 天內合併 148 個 PR)

描述

What would you like to be improved?

ConfigServlet#doGet catches IllegalStateException, IOException, and generic Exception but only logs them. It does not set an error status or return an error payload. If res.getWriter() or response writing fails (for example due to client disconnect or output stream failure), the endpoint can fail silently, leaving clients with an aborted/partial response and no explicit server-side HTTP failure signal.

How should we improve?

In ConfigServlet#doGet, when any exception occurs during response generation, set HttpServletResponse.SC_INTERNAL_SERVER_ERROR and return a small JSON error body (or at minimum set the status). Keep logging with exception context.

Here's a unit test to help:

  @Test
  public void testDoGetShouldSetInternalServerErrorWhenGetWriterFails() throws Exception {
    ConfigServlet configServlet = new ConfigServlet(new ServerConfig());
    HttpServletResponse response = mock(HttpServletResponse.class);
    when(response.getWriter()).thenThrow(new IOException("broken output stream"));

    configServlet.doGet(null, response);

    verify(response).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
  }

貢獻者指南