Brifing

How a Canceled Upload Reported Success

The detailed anatomy of a software bug.

ProAndroidDev - Medium3 min

1Discovery of the Bug

A developer team received a bug report in the demo version of their short-video SDK. When users canceled an upload, the progress bar stopped between 30% and 99%. However, the video appeared as processing in the grid. Upon refresh, the video disappeared. Despite never reaching the server, the app reported the upload as successful.

2Reproducing the Bug

The bug could not be reproduced on demand but eventually showed up over time. This made detection and resolution challenging. The report sat in the backlog for a while before a solution was found. The fix was smaller than the bug itself.

3Upload Process

In the SDK, uploads ran as tasks inside an executor. The base task class owned a simple contract. During upload, the task checked the cancellation flag and reported 'Done', 'Failed', or 'Canceled' accordingly. The grid listened to these notifications and displayed the appropriate state.

4Cancellation Operation

The cancellation operation worked by setting a flag and interrupting the task. However, this contract failed twice. The cancellation interrupted the task but did not set the flag, causing the upload to be reported as successful.

5Cancellation Flag Error

The cancellation flag was not set by the executor. This caused the flag to remain false during upload, leading to the upload being reported as successful. This resulted in a ghost entry appearing in the grid.

6Upload Library

Inside the upload library, the transfer was driven by a polling loop. This loop had been in use for years and was not designed for cancellable operations. During cancellation, the channel threw an exception, but it was caught, and the operation continued normally.

7Exception Handling

The polling loop treated a caught exception as a transient error and stopped looping. This caused the cancellation to go unnoticed. When the exception was caught, the upload appeared to complete normally.

8Flag Not Set

During cancellation, the flag was not set. This caused the flag to remain false during upload, leading to the upload being reported as successful. This resulted in a ghost entry appearing in the grid.

9Combined Effect of the Bug

When both errors combined, users received incorrect information. If the executor had set the flag, the upload would have been reported as canceled. If the polling loop had rethrown the exception, the upload would have been reported as canceled. However, both errors were open, causing the upload to be reported as successful.

10Resolution Process

The solution involved one line of code and two checkpoints. The executor checked the flag before setting it. The polling loop rethrew the exception. This resolved the bug. The fix was smaller than the bug itself.

11Importance of the Bug

This bug highlights an important point in software development. Cancellation operations must be handled carefully, and all layers must cooperate. Otherwise, users may receive incorrect information, leading to a loss of trust.

12Conclusion

This bug highlights an important point in software development. Cancellation operations must be handled carefully, and all layers must cooperate. Otherwise, users may receive incorrect information, leading to a loss of trust.

Original article: ProAndroidDev - Medium — İptal Edilen Yükleme Nasıl Başarılı Gösterdi?