apache / apache/beam

[Bug]: Exception from Downstream DoFn suppressed if upstream DoFn catches it on Dataflow Runner

Open
#31,505 1 comment 0 reactions 0 assignees View on GitHub
bug java P2 pinned
Dominant language
Java
Stars
8.7k
Forks
4.7k
Avg merge
1d 20h
Merged PRs (30d)
196

Description

### What happened?

Example:

```java

private static final Logger LOG = LoggerFactory.getLogger(DoFnErrorTest.class);
static class SomeDoFn extends DoFn {
@ProcessElement
public void process(@Element Long input, OutputReceiver receiver) {
try {
receiver.output(input);
} catch (Exception e) {
LOG.error("suppressing error", e);
}
}
}

static class ErrorDoFn extends DoFn {
@ProcessElement
public void process(ProcessContext ctx) {
Long element = ctx.element();
if (element == 1) {
throw new RuntimeException("Exception!");
}
}
}

public static void main(String[] argv) {
PipelineOptions options = PipelineOptionsFactory.fromArgs(argv).as(PipelineOptions.class);
Pipeline p = Pipeline.create(options);
p.apply(Create.of(0L, 1L, 2L))
.apply(ParDo.of(new DoFnErrorTest.SomeDoFn()))
.apply(ParDo.of(new DoFnErrorTest.ErrorDoFn()));
p.run().waitUntilFinish();
}
```

The pipeline failed (as expected) in direct runner, but it succeeded in Dataflow runner (legacy worker or runner v2)

Because Dataflow will fuse steps, and the output() of upstream DoFn essentially calling downstream DoFn's processElement (via reflection). If downstream process raised an Error, upstream DoFn can catch it.

imo This behavior is very confusing, and error prone. However I do not have a good idea to resolve it as it is deeply due to how Dataflow runner executes DoFns.

### Issue Priority

Priority: 2 (default / most bugs should be filed as P2)

### Issue Components

- [ ] Component: Python SDK
- [X] Component: Java SDK
- [ ] Component: Go SDK
- [ ] Component: Typescript SDK
- [ ] Component: IO connector
- [ ] Component: Beam YAML
- [ ] Component: Beam examples
- [ ] Component: Beam playground
- [ ] Component: Beam katas
- [ ] Component: Website
- [ ] Component: Spark Runner
- [ ] Component: Flink Runner
- [ ] Component: Samza Runner
- [ ] Component: Twister2 Runner
- [ ] Component: Hazelcast Jet Runner
- [ ] Component: Google Cloud Dataflow Runner

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.