为什么在 Linux 上从 Groovy 调用 C 程序时 RPC 调用失败?
我们有一个用 C 编写的程序,它使用 RPC 与同一 Linux 服务器上的另一个程序(也用 C 编写)进行通信(在某些生产设置中,第二个 C 程序将在另一台机器上,因此使用 RPC 而不是 IPC)。
当从其他 C 程序、CRON 或命令行调用时,它会按预期工作,并且多年来一直如此,因此可以肯定地说它通常可以工作。
从 Groovy 脚本调用的同一个程序失败了,显然是由于网络问题。
在 C 程序中,svc_register(xprt, prognum, versnum,dispatch, protocol)
成功,但在
- 请求后在 RPC 服务器上:
clnttcp_create
失败,并显示“连接被拒绝 - ” RPC 客户端等待回复:
svc_fdset
上的select
失败,并出现EBADF
看的):
[ "myprogram", "someoption", "someprogram" ].execute()
Groovy 程序(只是为了完整性,这里没什么可 我们尝试查明并解决问题?
We have a program, written in C, that uses RPC to communicate with another program (also written in C) on the same Linux server (in some production setups, the second C program would on another machine, therefore RPC instead of IPC).
When called from other C programs, CRON or the command line, it works as expected and has been doing so for many years, so it's safe to say it generally works.
The same program, called from a Groovy script, fails, apparently with network problems.
In the C program, svc_register(xprt, prognum, versnum, dispatch, protocol)
succeeds, but then
- on the RPC server after request:
clnttcp_create
fails with "connection refused" - on the RPC client waiting for reply:
select
onsvc_fdset
fails withEBADF
Groovy program (just for completeness, not much to see here):
[ "myprogram", "someoption", "someprogram" ].execute()
What could we try to pinpoint and fix the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
显然,从 Groovy 调用基于 RPC 的 C 程序确实有效。
问题可以缩小到“(int)sysconf (_SC_OPEN_MAX)”的问题,它用于确定 svc_fdset(用于从 rpc 请求获取回复的结构)中的 fd 数量,在使用时会失败由 Groovy 调用的 C 程序。
Apparently, calling RPC based C-programs from Groovy does indeed work.
The problem could be narrowed down to the issue that "(int)sysconf (_SC_OPEN_MAX)", which is used to determine the number of fds in svc_fdset (a structure used to get replies from rpc-requests) does fail in case of being used by a C program called from Groovy.
通过
strace
运行程序,看看有什么系统调用(s) 正在失败。Run the program through
strace
, to see what system call(s) is/are failing.检查
myprogram
是否有输出或等待输入。如果您不读取输出或关闭输入,那么它将挂起,导致 RPC 调用超时。创建一个线程,读取myprogram
的in
和err
并关闭out
:Check whether
myprogram
has output or waits for input. If you don't read the output or close the input, then it will hang, leading to timeouts in the RPC call. Create a thread which readsin
anderr
ofmyprogram
and closeout
: