Bug 212916

Summary: ResourceLoadStatisticsDatabaseStore::domainIDFromString failed, error message: bad parameter or other API misuse
Product: WebKit Reporter: Kate Cheney <katherine_cheney>
Component: WebKit Misc.Assignee: Kate Cheney <katherine_cheney>
Status: RESOLVED FIXED    
Severity: Normal CC: bfulgham, sihui_liu, webkit-bug-importer, wilander
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch for landing none

Description Kate Cheney 2020-06-08 13:15:56 PDT
The ResourceLoadStatisticsDatabaseStore is reporting "bad parameter or other API misuse" errors.
Comment 1 Kate Cheney 2020-06-08 13:16:15 PDT
<rdar://problem/64127238>
Comment 2 Kate Cheney 2020-06-08 13:25:32 PDT
Created attachment 401364 [details]
Patch
Comment 3 Sihui Liu 2020-06-08 14:06:22 PDT
Comment on attachment 401364 [details]
Patch

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

> Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:2226
> +    // Reset this statement because it will be used again in the same scope
> +    // when calling insertObservedDomain.
> +    scopedStatement->reset();

Can we put the scopedStatement in scope stead? like:
{
  auto scopedStatement = this->scopedStatement(m_domainIDFromStringStatement, domainIDFromStringQuery, "ensureResourceStatisticsForRegistrableDomain"_s);
    if (!scopedStatement
        || scopedStatement->bindText(1, domain.string()) != SQLITE_OK) {
        RELEASE_LOG_ERROR_IF_ALLOWED(m_sessionID, "%p - ResourceLoadStatisticsDatabaseStore::ensureResourceStatisticsForRegistrableDomain failed, error message: %{private}s", this, m_database.lastErrorMsg());
        ASSERT_NOT_REACHED();
        return { AddedRecord::No, 0 };
    }
    
    if (scopedStatement->step() == SQLITE_ROW) {
        unsigned domainID = scopedStatement->getColumnInt(0);
        return { AddedRecord::No, domainID };
    }
}
Comment 4 Kate Cheney 2020-06-08 14:51:31 PDT
Created attachment 401376 [details]
Patch
Comment 5 Kate Cheney 2020-06-08 14:52:33 PDT
(In reply to Sihui Liu from comment #3)
> Comment on attachment 401364 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=401364&action=review
> 
> > Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:2226
> > +    // Reset this statement because it will be used again in the same scope
> > +    // when calling insertObservedDomain.
> > +    scopedStatement->reset();
> 
> Can we put the scopedStatement in scope stead? like:
> {
>   auto scopedStatement =
> this->scopedStatement(m_domainIDFromStringStatement,
> domainIDFromStringQuery, "ensureResourceStatisticsForRegistrableDomain"_s);
>     if (!scopedStatement
>         || scopedStatement->bindText(1, domain.string()) != SQLITE_OK) {
>         RELEASE_LOG_ERROR_IF_ALLOWED(m_sessionID, "%p -
> ResourceLoadStatisticsDatabaseStore::
> ensureResourceStatisticsForRegistrableDomain failed, error message:
> %{private}s", this, m_database.lastErrorMsg());
>         ASSERT_NOT_REACHED();
>         return { AddedRecord::No, 0 };
>     }
>     
>     if (scopedStatement->step() == SQLITE_ROW) {
>         unsigned domainID = scopedStatement->getColumnInt(0);
>         return { AddedRecord::No, domainID };
>     }
> }

Yes, probably a better idea, I did this in the latest patch.
Comment 6 Sihui Liu 2020-06-08 16:05:49 PDT
Comment on attachment 401376 [details]
Patch

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

> Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:2211
> +{

Nit: indent the block
Comment 7 Kate Cheney 2020-06-08 16:09:33 PDT
Created attachment 401392 [details]
Patch for landing
Comment 8 EWS 2020-06-08 16:47:27 PDT
Committed r262752: <https://trac.webkit.org/changeset/262752>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 401392 [details].
Comment 9 Radar WebKit Bug Importer 2020-06-08 16:48:23 PDT
<rdar://problem/64140844>