javaasteriskagi

Asterisk Java AGI: utils.c write() returned error: Broken pipe


I have written a hello world Asterisk AGI script using Java. The script runs as expected and plays the hello world sound file, but the asterisk console is giving an error though:

ERROR[31058]: utils.c:1164 ast_carefulwrite: write() returned error: Broken pipe

Any idea what I'm doing wrong?

I'm using asterisk-java-0.3.1.jar and Asterisk 1.8.10.1~dfsg-1ubuntu1

Java class as below:

import org.asteriskjava.fastagi.AgiChannel;
import org.asteriskjava.fastagi.AgiException;
import org.asteriskjava.fastagi.AgiRequest;
import org.asteriskjava.fastagi.BaseAgiScript;

public class AgiHelloWorld extends BaseAgiScript 
{
    @Override
    public void service(AgiRequest arg0, AgiChannel arg1) throws AgiException 
    {
        answer();
        streamFile("hello-world");
        hangup();
    }
}

Solution

  • This error occurs when Asterisk tries to write some line to your AGI/FastAGI after script finish execution.

    Usually, asterisk send headers, and then waits for commands. After each command asterisk sends a response. But here is one exception, at the and it writes on more line

    HANGUP
    

    I think it is the line asterisk can`t write in your case. You can check it by turning on agi debug. Write in the console:

    agi set debug on
    

    and then after running your script you should see something like this:

        -- <SIP/XXXX-0000007c>AGI Script YOUR_AGI_NAME completed, returning 4
    <SIP/XXXX-0000007c>AGI Tx >> HANGUP
    ERROR[1502]: utils.c:1232 ast_carefulwrite: write() returned error: Broken pipe
    

    You can see that asterisk try to send HANGUP after script completed. You don`t have to worry about it, but it is a library bug.