当前位置: 首页 > 知识库问答 >
问题:

云运行应用程序在使用Micronaut HTTP客户端时以“503服务不可用”响应

益智明
2023-03-14

我的应用程序基于Micronaut和GraalVM(Java 11),并对http://httpbin.org/get:

@Controller("/api")
class HelloWorld(
    @Client("http://httpbin.org")
    private val httpClient: RxHttpClient
) {
    private val logger = LoggerFactory.getLogger(javaClass)

    @Get("/hello")
    fun hello(): String {
        return "Hello World!"
    }

    @Get("/fb")
    fun fb(): Flowable<String> {
        logger.info("Trying to call FB")
        logger.info("Using url http://httpbin.org/get")
        try {
            return httpClient.retrieve("/get")
                .doOnError { logger.error("Error calling fb api flowable", it) }
                .doFinally { logger.info("Finished calling FB api flowable") }
        } catch (ex: Exception) {
            logger.error("Error calling fb api", ex)
            throw ex
        } finally {
            logger.info("Finished calling fb api")
        }
    }
}

当我使用此DockerFile构建应用程序的docker映像时:

FROM maven:3.6.3-jdk-11 as maven
COPY . /home/app
WORKDIR /home/app
RUN mvn package

FROM oracle/graalvm-ce:19.3.1-java11 as graalvm
COPY --from=maven /home/app/target/app-*.jar /home/app/
WORKDIR /home/app
RUN gu install native-image
RUN native-image --no-server --enable-http --enable-https -cp app-*.jar

FROM debian:stretch
EXPOSE 8080
COPY --from=graalvm /home/app/app .
#RUN apt-get update && apt-get -y install strace
ENTRYPOINT ["./app"]

在我当地的环境里一切都正常。但当我将映像推送到Google Cloud Repository,将其部署到Cloud Run,并尝试访问endpoint/api/fb时,容器会崩溃,因为503服务不可用。

日志中的错误是“请求失败,因为到实例的HTTP连接有一个错误”。启用strace时,以下是日志:

A 2020-02-07T12:04:27.443115Z [pid    18] <... futex resumed> )       = -1 ETIMEDOUT (Connection timed out) 
A 2020-02-07T12:04:27.443125Z [pid    18] futex(0x3e61dc018a80, FUTEX_WAKE_PRIVATE, 1) = 0 
A 2020-02-07T12:04:27.443357Z [pid    18] futex(0x3e62040009c4, FUTEX_CMP_REQUEUE_PRIVATE, 1, 2147483647, 0x3e6204000990, 234) = 1 
A 2020-02-07T12:04:27.443369Z [pid    15] <... futex resumed> )       = 0 
A 2020-02-07T12:04:27.443440Z [pid    18] futex(0x3e61dc018ab4, FUTEX_WAIT_BITSET_PRIVATE, 157, {tv_sec=3624, tv_nsec=391761056}, 0xffffffff <unfinished ...> 
A 2020-02-07T12:04:27.443478Z [pid    15] futex(0x3e6204000990, FUTEX_WAKE_PRIVATE, 1) = 0 
A 2020-02-07T12:04:27.959629Z [pid    20] epoll_wait(17,  <unfinished ...> 
A 2020-02-07T12:04:27.959658Z [pid     8] <... epoll_wait resumed> [{EPOLLIN, {u32=53, u64=53}}], 1024, -1) = 1 
A 2020-02-07T12:04:27.959865Z [pid     8] accept(53, {sa_family=AF_INET6, sin6_port=htons(36294), inet_pton(AF_INET6, "::ffff:169.254.8.129", &sin6_addr), sin6_flowinfo=htonl(0), sin6_scope_id=0}, [28]) = 4 
A 2020-02-07T12:04:27.959884Z [pid     8] fcntl(4, F_GETFL)           = 0x2 (flags O_RDWR) 
A 2020-02-07T12:04:27.959945Z [pid     8] getsockname(4, {sa_family=AF_INET6, sin6_port=htons(8080), inet_pton(AF_INET6, "::ffff:169.254.8.130", &sin6_addr), sin6_flowinfo=htonl(0), sin6_scope_id=0}, [28]) = 0 
A 2020-02-07T12:04:27.960036Z [pid     8] getsockname(4, {sa_family=AF_INET6, sin6_port=htons(8080), inet_pton(AF_INET6, "::ffff:169.254.8.130", &sin6_addr), sin6_flowinfo=htonl(0), sin6_scope_id=0}, [28]) = 0 
A 2020-02-07T12:04:27.960085Z [pid     8] fcntl(4, F_GETFL)           = 0x2 (flags O_RDWR) 
A 2020-02-07T12:04:27.960128Z [pid     8] fcntl(4, F_SETFL, O_RDWR|O_NONBLOCK) = 0 
A 2020-02-07T12:04:27.960211Z [pid     8] setsockopt(4, SOL_TCP, TCP_NODELAY, [1], 4) = 0 
A 2020-02-07T12:04:27.960322Z [pid     8] getsockopt(4, SOL_SOCKET, SO_SNDBUF, [1048576], [4]) = 0 
A 2020-02-07T12:04:27.960440Z [pid     8] mmap(NULL, 8392704, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x3e60f0e00000 
A 2020-02-07T12:04:27.960564Z [pid     8] mprotect(0x3e60f0e00000, 4096, PROT_NONE) = 0 
A 2020-02-07T12:04:27.960793Z [pid     8] clone(/usr/bin/strace: Process 22 attached 
A 2020-02-07T12:04:27.960875Z  <unfinished ...> 
A 2020-02-07T12:04:27.965711Z [pid    22] set_robust_list(0x3e60f16009e0, 24 <unfinished ...> 
A 2020-02-07T12:04:27.965738Z [pid     8] <... clone resumed> child_stack=0x3e60f15fffb0, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x3e60f16009d0, tls=0x3e60f1600700, child_tidptr=0x3e60f16009d0) = 22 
A 2020-02-07T12:04:27.965753Z [pid    22] <... set_robust_list resumed> ) = -1 ENOSYS (Function not implemented) 
A 2020-02-07T12:04:27.965761Z [pid     8] epoll_wait(29,  <unfinished ...> 
A 2020-02-07T12:04:27.965770Z [pid    22] sched_getaffinity(22, 32, [0, 1]) = 8 
A 2020-02-07T12:04:27.965783Z [pid    22] futex(0x3b4c0c4, FUTEX_CMP_REQUEUE_PRIVATE, 1, 2147483647, 0x3b4c068, 30) = 1 
A 2020-02-07T12:04:27.965790Z [pid     3] <... futex resumed> )       = 0 
A 2020-02-07T12:04:27.965799Z [pid     3] futex(0x3b4c068, FUTEX_WAIT_PRIVATE, 2, NULL <unfinished ...> 
A 2020-02-07T12:04:27.965807Z [pid    22] futex(0x3b4c068, FUTEX_WAKE_PRIVATE, 1) = 1 
A 2020-02-07T12:04:27.965816Z [pid    22] mmap(NULL, 2097152, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0 <unfinished ...> 
A 2020-02-07T12:04:27.965824Z [pid     3] <... futex resumed> )       = 0 
A 2020-02-07T12:04:27.965833Z [pid     3] futex(0x3b4c068, FUTEX_WAKE_PRIVATE, 1 <unfinished ...> 
A 2020-02-07T12:04:27.965842Z [pid    22] <... mmap resumed> )        = 0x3e60f0c00000 
A 2020-02-07T12:04:27.965850Z [pid     3] <... futex resumed> )       = 0 
A 2020-02-07T12:04:27.965858Z [pid     3] futex(0x3b4c0c4, FUTEX_WAIT_PRIVATE, 31, NULL <unfinished ...> 
A 2020-02-07T12:04:27.965866Z [pid    22] munmap(0x3e60f0d00000, 1048576) = 0 
A 2020-02-07T12:04:27.965874Z [pid    22] prctl(PR_SET_NAME, "ntLoopGroup-1-7"...) = 0 
A 2020-02-07T12:04:27.965882Z [pid    22] epoll_wait(20, [], 1024, 0) = 0 
A 2020-02-07T12:04:27.965891Z [pid    22] mmap(NULL, 2097152, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x3e60f0a00000 
A 2020-02-07T12:04:27.965903Z [pid    22] munmap(0x3e60f0b00000, 1048576) = 0 
A 2020-02-07T12:04:27.966731Z [pid    22] epoll_ctl(20, EPOLL_CTL_ADD, 4, {EPOLLIN, {u32=4, u64=4}}) = 0 
A 2020-02-07T12:04:27.966836Z [pid    22] epoll_wait(20, [{EPOLLIN, {u32=4, u64=4}}], 1024, 299996) = 1 
A 2020-02-07T12:04:27.967306Z [pid    22] mmap(NULL, 2097152, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x3e60f0800000 
A 2020-02-07T12:04:27.967325Z [pid    22] munmap(0x3e60f0900000, 1048576) = 0 
A 2020-02-07T12:04:27.967493Z [pid    22] mmap(NULL, 16781312, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x3e60ef600000 
A 2020-02-07T12:04:27.984977Z [pid    22] read(4, "GET /api/fb HTTP/1.1\r\nhost: app"..., 1024) = 864 
A 2020-02-07T12:04:27.985474Z [36m12:04:27.985[0;39m [1;30m[nioEventLoopGroup-1-7][0;39m [34mINFO [0;39m [35mcom.roihunter.app.HelloWorld[0;39m - Trying to call FB 
A 2020-02-07T12:04:27.985581Z [36m12:04:27.985[0;39m [1;30m[nioEventLoopGroup-1-7][0;39m [34mINFO [0;39m [35mcom.roihunter.app.HelloWorld[0;39m - Using url /act_984750788289990/insights 
A 2020-02-07T12:04:27.985645Z [pid    22] write(1, "\33[36m12:04:27.985\33[0;39m \33[1;30m"..., 143) = 143 
A 2020-02-07T12:04:27.985666Z [pid    22] write(1, "\33[36m12:04:27.985\33[0;39m \33[1;30m"..., 165) = 165 
A 2020-02-07T12:04:27.985766Z [36m12:04:27.985[0;39m [1;30m[nioEventLoopGroup-1-7][0;39m [34mINFO [0;39m [35mcom.roihunter.app.HelloWorld[0;39m - Finished calling fb api 
A 2020-02-07T12:04:27.985836Z [pid    22] write(1, "\33[36m12:04:27.985\33[0;39m \33[1;30m"..., 149) = 149 
A 2020-02-07T12:04:27.986363Z [pid    22] write(4, "HTTP/1.1 200 OK\r\ntransfer-encodi"..., 143) = 143 
E 2020-02-07T12:04:27.988626Z GET 503 546 B 31 ms curl/7.66.0 https://app-5phkf6s3jq-ez.a.run.app/api/fb GET 503 546 B 31 ms curl/7.66.0 
A 2020-02-07T12:04:27.989104Z [pid    22] writev(4, [{iov_base="1\r\n", iov_len=3}, {iov_base="[", iov_len=1}, {iov_base="\r\n", iov_len=2}], 3) = 6 
A 2020-02-07T12:04:27.989513Z [pid    22] mmap(NULL, 8392704, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x3e60eec00000 
A 2020-02-07T12:04:27.989534Z [pid    22] mprotect(0x3e60eec00000, 4096, PROT_NONE) = 0 
A 2020-02-07T12:04:27.989732Z [pid    22] clone(/usr/bin/strace: Process 23 attached 
A 2020-02-07T12:04:27.989753Z  <unfinished ...> 
A 2020-02-07T12:04:27.989873Z [pid    23] set_robust_list(0x3e60ef4009e0, 24) = -1 ENOSYS (Function not implemented) 
A 2020-02-07T12:04:27.989884Z [pid    23] sched_getaffinity(23, 32, [0, 1]) = 8 
A 2020-02-07T12:04:27.989964Z [pid    23] futex(0x3b4c0c4, FUTEX_CMP_REQUEUE_PRIVATE, 1, 2147483647, 0x3b4c068, 32) = 1 
A 2020-02-07T12:04:27.990286Z [pid    23] mmap(NULL, 2097152, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0 <unfinished ...> 
A 2020-02-07T12:04:27.990303Z [pid    22] <... clone resumed> child_stack=0x3e60ef3fffb0, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x3e60ef4009d0, tls=0x3e60ef400700, child_tidptr=0x3e60ef4009d0) = 23 
A 2020-02-07T12:04:27.990311Z [pid    23] <... mmap resumed> )        = 0x3e60eea00000 
A 2020-02-07T12:04:27.990320Z [pid     3] <... futex resumed> )       = 0 
A 2020-02-07T12:04:27.990327Z [pid     3] futex(0x3b4c068, FUTEX_WAKE_PRIVATE, 1) = 0 
A 2020-02-07T12:04:27.990335Z [pid     3] futex(0x3b4c0c4, FUTEX_WAIT_PRIVATE, 33, NULL <unfinished ...> 
A 2020-02-07T12:04:27.990345Z [pid    23] munmap(0x3e60eeb00000, 1048576) = 0 
A 2020-02-07T12:04:27.990423Z [pid    22] socket(AF_INET6, SOCK_STREAM, IPPROTO_IP <unfinished ...> 
A 2020-02-07T12:04:27.990435Z [pid    23] prctl(PR_SET_NAME, "ionThreadPool-1"... <unfinished ...> 
A 2020-02-07T12:04:27.990446Z [pid    22] <... socket resumed> )      = 80 
A 2020-02-07T12:04:27.990668Z [pid    22] setsockopt(80, SOL_IPV6, IPV6_V6ONLY, [0], 4) = 0 
A 2020-02-07T12:04:27.990684Z [pid    23] <... prctl resumed> )       = 0 

我尝试使用一个不同的库进行调用,Java 11 Http客户端,它起作用了。但是无论我做什么,当我使用Micronaut Http客户端时都不起作用,而且没有任何有帮助的消息。

我也尝试过在docker映像中使用Java 8,一个不同的linux发行版(Fedora:latest,Ubuntu:latest),但没有帮助。

你知道是什么引起的吗?

谢谢你提前回答。

共有2个答案

公孙成仁
2023-03-14

所以问题的核心似乎是Cloud Run目前不支持HTTP流:

https://cloud.google.com/run/docs/issues#grpc_websocket

当我返回Flowable with Micronauts时,它正在打开一个streamable HTTP连接。因此,解决方案不是使用Flowable(或任何其他无界的发布者,例如Flow、Flux等)作为响应。

訾安邦
2023-03-14

好的。因为这是每当有人搜索Cloud run 503 Error时出现的唯一问题,所以我想分享一下我的可怕经验和解决方案

我在cloud run上部署了我的spring boot应用程序,并为其配置了pub-sub推送订阅触发器。我在本地系统上测试过。然后我在我的私人GCP项目上测试了它。然后当我在组织的GCP帐户上部署它时,我开始得到503个错误。

在此之后,下面是我尝试的。

  1. 我尝试通过授予max权限来更改默认服务帐户(由run实例使用)的角色/权限,但没有用。
  2. 尝试将并发更改为1(按照GCP文档中的建议),但没有帮助。
  3. 我开始将运行实例的每个配置与专用GCP运行实例进行比较,然后发现我错误地选中了下面的选项,这导致了此问题。

所以我取消了它,重新部署了我的实例,它工作了。

 类似资料:
  • 当我使用以下dockerfile构建应用程序的docker映像时: 一切都在我当地的环境中工作。但是,当我将映像推送到Google Cloud Repository,将其部署到Cloud Run并尝试访问endpoint时,容器崩溃,503服务不可用。 日志中的错误是“请求失败,因为到实例的HTTP连接有错误”。当我启用strace时,以下是日志: 谢谢你提前回答。

  • 根据微软的文档,Application Insights最好在构建时和运行时部署,并且可以通过“在应用程序的Azure控制面板上选择[ing]Application Insights”在运行时安装。但我在云服务的配置上没有看到它,至少在新门户中没有: 文档是否不正确(使得其他地方所列的长流程仍然是必需的)?如果没有,我应该去哪里找呢?

  • 问题内容: 我正在尝试以客户端/服务器方式制作Java应用程序。客户端是SWT中的GUI,它显示来自服务器的数据。服务器已连接到数据库。 好的,对此感到抱歉,我确定这是一个经典问题,但我不知道如何开始。 在我为他们工作的一个项目中,他们实施了很多魔术来透明地调用Glassfish服务器。 我不想使用Glassfish服务器。我只想要简单的Java语言。但是代理的概念似乎很酷。 你有这种想法或例子吗

  • 问题内容: 我使用nio频道构建了一个简单的聊天应用程序。我对网络和线程非常陌生。该应用程序用于与服务器通信(服务器/客户端聊天应用程序)。 我的问题是服务器不支持多个客户端。我该如何解决这个问题?我的代码中的错误是什么? 问题答案: 初学者Hello NIO Server的 理想之地

  • 我找到了在Azure App服务下运行一个简单的Node only应用程序的示例。但是对于ExpressJS,我找到的示例都使用了Azure云服务。刚开始使用Azure,只是想弄清楚我应该使用什么。 简单的NodeJS到Azure应用程序服务https://Azure.microsoft.com/en-us/documentation/articles/web-sites-nodeJs-devel

  • 我正在编写一个客户机-服务器应用程序,但在使用命令模式时遇到了问题。在我的程序中,服务器从客户端接收字符串输入命令,在HashMap中为输入找到合适的命令,执行它并返回返回值。我在弄清楚如何编写需要不止一步的命令时遇到了问题(命令必须要求客户机提供额外的参数,然后应该返回最终结果)。 命令界面 服务器与客户端的通信 一步到位,毫无问题 我不知道如何编写一个命令,它需要一个额外的参数来执行,它不能在