Bug 189822 - Apache can return a corrupt manifest file while ManifestGenerator::store is running
Summary: Apache can return a corrupt manifest file while ManifestGenerator::store is r...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-21 02:14 PDT by dewei_zhu
Modified: 2018-09-26 23:30 PDT (History)
2 users (show)

See Also:


Attachments
Patch (8.38 KB, patch)
2018-09-21 02:23 PDT, dewei_zhu
no flags Details | Formatted Diff | Diff
Patch (10.35 KB, patch)
2018-09-24 21:39 PDT, dewei_zhu
rniwa: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description dewei_zhu 2018-09-21 02:14:50 PDT
Generating manifest.json should be transactional.
Comment 1 dewei_zhu 2018-09-21 02:23:35 PDT
Created attachment 350341 [details]
Patch
Comment 2 Ryosuke Niwa 2018-09-21 22:47:51 PDT
Comment on attachment 350341 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=350341&action=review

r-. There are enough problems in this patch that I'd like to see another iteration.

> Websites/perf.webkit.org/ChangeLog:3
> +        Updating file on perf-safari should be transactional between php and apache.

We shouldn't mention perf-safari. I've updated the bug title. Please update the change log as well.

> Websites/perf.webkit.org/public/api/measurement-set.php:41
> +    $json = NULL;

Please declare these variables inside the loop.
Also, there is no point in declaring $json.

> Websites/perf.webkit.org/public/api/measurement-set.php:55
> +        $content['elapsedTime'] = $elapsed_time;
> +        $json = json_encode($content);
> +        generate_json_data_conditionally($cache_filename, $json, 'elapsedTime');

I don't think we want to rely on elapsedTime being the last item like this.
Pass in $elapsed_time as the last argument to generate_json_data_conditionally instead:
generate_json_data_conditionally($cache_filename, $content, $elapsed_time);
It's better to invoke json_encode in generate_json_data_conditionally instead.
Also, we should probably call this generate_json_data_if_needed to match the naming convention used elsewhere in WebKit.

> Websites/perf.webkit.org/public/include/db.php:65
> +    $target_file_path = config_path('dataDirectory', $filename);
> +    $temp_file_path = tempnam(config_path('dataDirectory', ''), $filename . '-temp-');

Why do we need to make a temporary file before comparing the content?

> Websites/perf.webkit.org/public/include/json-header.php:17
> +function set_success(&$details = array()) {

This should be set_successful instead.
Comment 3 dewei_zhu 2018-09-24 14:43:10 PDT
Comment on attachment 350341 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=350341&action=review

>> Websites/perf.webkit.org/public/api/measurement-set.php:55
>> +        generate_json_data_conditionally($cache_filename, $json, 'elapsedTime');
> 
> I don't think we want to rely on elapsedTime being the last item like this.
> Pass in $elapsed_time as the last argument to generate_json_data_conditionally instead:
> generate_json_data_conditionally($cache_filename, $content, $elapsed_time);
> It's better to invoke json_encode in generate_json_data_conditionally instead.
> Also, we should probably call this generate_json_data_if_needed to match the naming convention used elsewhere in WebKit.

If do so, we need to make generate_json_date_conditinally returns an encoded json to void calling json_encode twice as it is needed in Lin 58.
Comment 4 Ryosuke Niwa 2018-09-24 15:21:53 PDT
Comment on attachment 350341 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=350341&action=review

>>> Websites/perf.webkit.org/public/api/measurement-set.php:55
>>> +        generate_json_data_conditionally($cache_filename, $json, 'elapsedTime');
>> 
>> I don't think we want to rely on elapsedTime being the last item like this.
>> Pass in $elapsed_time as the last argument to generate_json_data_conditionally instead:
>> generate_json_data_conditionally($cache_filename, $content, $elapsed_time);
>> It's better to invoke json_encode in generate_json_data_conditionally instead.
>> Also, we should probably call this generate_json_data_if_needed to match the naming convention used elsewhere in WebKit.
> 
> If do so, we need to make generate_json_date_conditinally returns an encoded json to void calling json_encode twice as it is needed in Lin 58.

Yeah, that's fine.
Comment 5 dewei_zhu 2018-09-24 21:39:42 PDT
Created attachment 350736 [details]
Patch
Comment 6 Ryosuke Niwa 2018-09-24 21:50:52 PDT
Comment on attachment 350736 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=350736&action=review

> Websites/perf.webkit.org/ChangeLog:8
> +        Updating a file on should be transactional between php and apache.

Updating a file *on* what??

> Websites/perf.webkit.org/ChangeLog:11
> +        * public/api/measurement-set.php: Adapted invocation of 'generate_json_date_with_elapsed_time_if needed'.

Nit: Somehow the function name has a space instead of _ between if and needed.

> Websites/perf.webkit.org/ChangeLog:12
> +        * public/api/runs.php: Adapted invocation of 'generate_json_date_with_elapsed_time_if needed'.

Ditto.
Comment 7 dewei_zhu 2018-09-26 23:30:37 PDT
Landed in r236454.