worker always returns an empty string for Warnings and Exceptions

Bug #1126496 reported by Khai Do
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Gearman Java
Fix Released
Undecided
Eric Lambert

Bug Description

It looks like the worker always returns an empty string for getExceptions() and getWarnings(). It doesn't matter whether the worker function succeeded or failed.

I used the reverse worker and client examples to test...

Worker:

public class ReverseFunction extends AbstractGearmanFunction {

    @Override
    public GearmanJobResult executeFunction() {

        boolean jobResult = false;

        RuntimeException re = new RuntimeException("job Failed!");
        String warningMsg = "Test the warning";

        StringBuffer sb = new StringBuffer(ByteUtils.fromUTF8Bytes((byte[]) this.data));

        // tested by throwing an exception but still do not get warnings or exceptions on client side
        // throw re;

        GearmanJobResult gjr = new GearmanJobResultImpl(this.jobHandle,
                jobResult, sb.reverse().toString().getBytes(),
                warningMsg.getBytes(), re.toString().getBytes(), 0, 0);
        return gjr;
    }
}

Client:

    public String reverse(String input) {
        String function = ReverseFunction.class.getCanonicalName();
        String uniqueId = null;
        byte[] data = ByteUtils.toUTF8Bytes(input);
        GearmanJobResult res = null;
        GearmanJob job = GearmanJobImpl.createJob(function, data, uniqueId);
        String value = "";
        String valueWarn = "";
        String valueEx = "";

        client.submit(job);

        try {
            res = job.get();
            if (res.jobSucceeded()){
                value = ByteUtils.fromUTF8Bytes(res.getResults());
                valueEx = ByteUtils.fromUTF8Bytes(res.getExceptions());
                valueWarn = ByteUtils.fromUTF8Bytes(res.getWarnings());
            } else {
                value = ByteUtils.fromUTF8Bytes(res.getResults());
                valueEx = ByteUtils.fromUTF8Bytes(res.getExceptions());
                valueWarn = ByteUtils.fromUTF8Bytes(res.getWarnings());

            }
        } catch (Exception e) {
            e.printStackTrace(); //NOPMD
        }

        String resultMsg = value.toString()+","+valueWarn.toString()+","+valueEx.toString();
        return resultMsg; // never get anything for res.getWarnings() or res.getExceptions()
    }

Revision history for this message
Khai Do (zaro0508) wrote :

My Environment:
  using gearman-java-0.6-SNAPSHOT
  Dev machine: Ubuntu SMP Tue Jan 8 21:41:11 UTC 2013 i686 i686 i686 GNU/Linux
  gearman server: gearmand ver. 0.27 on Ubuntu SMP Wed Sep 26 21:53:42 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

Eric Lambert (elambert)
Changed in gearman-java:
assignee: nobody → Eric Lambert (elambert)
milestone: none → 0.06
Eric Lambert (elambert)
Changed in gearman-java:
status: New → Confirmed
Eric Lambert (elambert)
Changed in gearman-java:
status: Confirmed → In Progress
Eric Lambert (elambert)
Changed in gearman-java:
status: In Progress → Fix Committed
Revision history for this message
Eric Lambert (elambert) wrote :

Khai:

I've committed a fix for this. Now if your function throws an exception, the stack trace for that exception should be available by calling getExceptions on the job result --as I write this it occurred to me that perhaps the stack trace is not always what you might want here, let me know if that is an issue.

In case you are interested, the main problem was that by default the Gearman Job Server does not forward WORK_EXCEPTION packets back to the client. This needs to be enabled by the client on a per-connection basis which the client was not doing. As part of this fix, the client now by default will enable this behavior.

Also, if the GearmanJobResult given back to the worker from the function has any warnings, those too should be sent back to the client.

If you have questions about how these work you can either let me know or see the GearmanClientJobExecTest test-suite, specifically looking at the exceptionThrownDuringFunctionTest, excectionThrownNotPassedToClient, and warningTest test cases.

Eric

PS

I refrained from pushing this fix to my maven SNAPSHOT repo as based on our last email exchange it seemed like you might be pulling from SNAPSHOT latest and I wanted to give you a chance to look at this before it appeared in your environment.

Also, assuming no major issues with this patch, i suspect I will be releasing 0.06 soon

Revision history for this message
Khai Do (zaro0508) wrote :

Hi Eric. I have verified this fix. It works exactly as i expect. Thanks for the detailed info because i'm experiencing the same problem when I use the python client with this worker. Please do your release so I can pickup from the repo. Thanks!

Revision history for this message
Eric Lambert (elambert) wrote : Re: [Bug 1126496] worker always returns an empty string for Warnings and Exceptions

Snapshot deployed ...
On Mar 5, 2013, at 3:55 PM, Khai Do wrote:

> Hi Eric. I have verified this fix. It works exactly as i expect.
> Thanks for the detailed info because i'm experiencing the same problem
> when I use the python client with this worker. Please do your release
> so I can pickup from the repo. Thanks!
>
> --
> You received this bug notification because you are a bug assignee.
> https://bugs.launchpad.net/bugs/1126496
>
> Title:
> worker always returns an empty string for Warnings and Exceptions
>
> Status in Gearman Java:
> Fix Committed
>
> Bug description:
> It looks like the worker always returns an empty string for
> getExceptions() and getWarnings(). It doesn't matter whether the
> worker function succeeded or failed.
>
> I used the reverse worker and client examples to test...
>
> Worker:
>
> public class ReverseFunction extends AbstractGearmanFunction {
>
> @Override
> public GearmanJobResult executeFunction() {
>
> boolean jobResult = false;
>
> RuntimeException re = new RuntimeException("job Failed!");
> String warningMsg = "Test the warning";
>
>
> StringBuffer sb = new StringBuffer(ByteUtils.fromUTF8Bytes((byte[]) this.data));
>
> // tested by throwing an exception but still do not get warnings or exceptions on client side
> // throw re;
>
> GearmanJobResult gjr = new GearmanJobResultImpl(this.jobHandle,
> jobResult, sb.reverse().toString().getBytes(),
> warningMsg.getBytes(), re.toString().getBytes(), 0, 0);
> return gjr;
> }
> }
>
>
> Client:
>
>
> public String reverse(String input) {
> String function = ReverseFunction.class.getCanonicalName();
> String uniqueId = null;
> byte[] data = ByteUtils.toUTF8Bytes(input);
> GearmanJobResult res = null;
> GearmanJob job = GearmanJobImpl.createJob(function, data, uniqueId);
> String value = "";
> String valueWarn = "";
> String valueEx = "";
>
>
> client.submit(job);
>
> try {
> res = job.get();
> if (res.jobSucceeded()){
> value = ByteUtils.fromUTF8Bytes(res.getResults());
> valueEx = ByteUtils.fromUTF8Bytes(res.getExceptions());
> valueWarn = ByteUtils.fromUTF8Bytes(res.getWarnings());
> } else {
> value = ByteUtils.fromUTF8Bytes(res.getResults());
> valueEx = ByteUtils.fromUTF8Bytes(res.getExceptions());
> valueWarn = ByteUtils.fromUTF8Bytes(res.getWarnings());
>
> }
> } catch (Exception e) {
> e.printStackTrace(); //NOPMD
> }
>
> String resultMsg = value.toString()+","+valueWarn.toString()+","+valueEx.toString();
> return resultMsg; // never get anything for res.getWarnings() or res.getExceptions()
> }
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/gearman-java/+bug/1126496/+subscriptions

Eric Lambert (elambert)
Changed in gearman-java:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.