WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
224305
Create WebIDBServer only when it is needed
https://bugs.webkit.org/show_bug.cgi?id=224305
Summary
Create WebIDBServer only when it is needed
Sihui Liu
Reported
2021-04-07 14:42:49 PDT
...
Attachments
Patch
(16.74 KB, patch)
2021-04-07 15:02 PDT
,
Sihui Liu
no flags
Details
Formatted Diff
Diff
Patch
(17.16 KB, patch)
2021-04-07 20:53 PDT
,
Sihui Liu
no flags
Details
Formatted Diff
Diff
Patch
(16.94 KB, patch)
2021-04-08 10:58 PDT
,
Sihui Liu
no flags
Details
Formatted Diff
Diff
Patch
(17.37 KB, patch)
2021-04-08 14:21 PDT
,
Sihui Liu
no flags
Details
Formatted Diff
Diff
Patch
(17.40 KB, patch)
2021-04-08 16:01 PDT
,
Sihui Liu
no flags
Details
Formatted Diff
Diff
Patch for landing
(17.57 KB, patch)
2021-04-09 14:07 PDT
,
Sihui Liu
no flags
Details
Formatted Diff
Diff
Patch for landing
(17.66 KB, patch)
2021-04-09 14:21 PDT
,
Sihui Liu
no flags
Details
Formatted Diff
Diff
Patch for landing
(17.63 KB, patch)
2021-04-09 14:22 PDT
,
Sihui Liu
no flags
Details
Formatted Diff
Diff
[fast-cq] Patch
(1.95 KB, patch)
2021-04-09 16:52 PDT
,
Sihui Liu
no flags
Details
Formatted Diff
Diff
[fast-cq] Patch
(1.84 KB, patch)
2021-04-10 01:30 PDT
,
Sihui Liu
ews-feeder
: commit-queue-
Details
Formatted Diff
Diff
[fast-cq] Patch
(1.82 KB, patch)
2021-04-10 01:37 PDT
,
Sihui Liu
no flags
Details
Formatted Diff
Diff
Patch for landing
(14.65 KB, patch)
2021-04-10 09:23 PDT
,
Sihui Liu
ews-feeder
: commit-queue-
Details
Formatted Diff
Diff
Patch for landing
(15.15 KB, patch)
2021-04-10 09:48 PDT
,
Sihui Liu
no flags
Details
Formatted Diff
Diff
Patch
(18.67 KB, patch)
2021-04-12 08:28 PDT
,
Sihui Liu
no flags
Details
Formatted Diff
Diff
Show Obsolete
(13)
View All
Add attachment
proposed patch, testcase, etc.
Sihui Liu
Comment 1
2021-04-07 14:43:19 PDT
rdar://71962196
Sihui Liu
Comment 2
2021-04-07 15:02:23 PDT
Created
attachment 425445
[details]
Patch
Sihui Liu
Comment 3
2021-04-07 20:53:15 PDT
Created
attachment 425475
[details]
Patch
Alex Christensen
Comment 4
2021-04-08 09:23:08 PDT
Comment on
attachment 425475
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=425475&action=review
> Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.cpp:70 > + postTaskReply(CrossThreadTask([this, callback = WTFMove(callback), origins = crossThreadCopy(m_server->getOrigins())]() mutable {
Don't we need either a protected or a weak this here?
> Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.cpp:88 > + postTaskReply(CrossThreadTask([this, callback = WTFMove(callback)]() mutable {
ditto
> Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.cpp:106 > + postTaskReply(CrossThreadTask([this, callback = WTFMove(callback)]() mutable {
ditto
Sihui Liu
Comment 5
2021-04-08 10:58:05 PDT
Created
attachment 425521
[details]
Patch
Sihui Liu
Comment 6
2021-04-08 11:01:40 PDT
(In reply to Alex Christensen from
comment #4
)
> Comment on
attachment 425475
[details]
> Patch > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=425475&action=review
> > > Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.cpp:70 > > + postTaskReply(CrossThreadTask([this, callback = WTFMove(callback), origins = crossThreadCopy(m_server->getOrigins())]() mutable { > > Don't we need either a protected or a weak this here? >
Updated the patch. By the way do you think revealing sessionID in thread name is a bad idea?
Darin Adler
Comment 7
2021-04-08 11:07:05 PDT
Comment on
attachment 425521
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=425521&action=review
This looks good. I have some comments. I didn’t set review+ because I am not sure I’m enough of an expert on this area to spot mistakes, but I think it looks right.
> Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.h:97 > + enum class DataTaskCountUpdateType : uint8_t { Decrease, Increase }; > + void updateDataTaskCount(DataTaskCountUpdateType);
This is a peculiar interface. I suggest two separate named functions rather than a function with an enum class argument. Also, to try to make this harder to get wrong, I suggest we make an object that increments on creation and decrements on destruction. We can capture that object in lambdas, instead of capturing "protectedThis" and writing an explicit decrement function.
> Source/WebKit/NetworkProcess/NetworkProcess.cpp:2675 > + if (auto* webIDBServer = m_webIDBServers.get(sessionID)) > + webIDBServer->removeConnection(connection);
In a tight context like this, I really like single word variable names that don’t try to disambiguate or be precise. Like: if (auto server = m_webIDBServers.get(sessionID)) server->removeConnection(connection); Sure, the local variable can be named webIDBServer or even webIDBServerForSession, but it doesn’t need to be. Single words work really well to make such code clear and readable.
Sihui Liu
Comment 8
2021-04-08 14:21:42 PDT
Created
attachment 425542
[details]
Patch
Sihui Liu
Comment 9
2021-04-08 14:23:02 PDT
(In reply to Darin Adler from
comment #7
)
> Comment on
attachment 425521
[details]
> Patch > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=425521&action=review
> > This looks good. I have some comments. I didn’t set review+ because I am not > sure I’m enough of an expert on this area to spot mistakes, but I think it > looks right. > > > Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.h:97 > > + enum class DataTaskCountUpdateType : uint8_t { Decrease, Increase }; > > + void updateDataTaskCount(DataTaskCountUpdateType); > > This is a peculiar interface. I suggest two separate named functions rather > than a function with an enum class argument. > > Also, to try to make this harder to get wrong, I suggest we make an object > that increments on creation and decrements on destruction. We can capture > that object in lambdas, instead of capturing "protectedThis" and writing an > explicit decrement function. >
Thanks for the comments. I've replaced it with a RefCounter.
> > Source/WebKit/NetworkProcess/NetworkProcess.cpp:2675 > > + if (auto* webIDBServer = m_webIDBServers.get(sessionID)) > > + webIDBServer->removeConnection(connection); > > In a tight context like this, I really like single word variable names that > don’t try to disambiguate or be precise. Like: > > if (auto server = m_webIDBServers.get(sessionID)) > server->removeConnection(connection); > > Sure, the local variable can be named webIDBServer or even > webIDBServerForSession, but it doesn’t need to be. Single words work really > well to make such code clear and readable.
Updated.
Darin Adler
Comment 10
2021-04-08 15:30:46 PDT
Comment on
attachment 425542
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=425542&action=review
> Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.cpp:44 > + , m_dataTaskCounter([protectedThis = makeRef(*this)](RefCounterEvent event) { protectedThis->tryClose(); })
This creates a reference cycle since the WebIDBServer owns its m_dataTaskCounter, which in turn owns this lambda, which in turn references the WebIDBServer, so I think the WebIDBServer will leak.
Sihui Liu
Comment 11
2021-04-08 16:01:37 PDT
Created
attachment 425555
[details]
Patch
Alex Christensen
Comment 12
2021-04-09 10:55:20 PDT
Comment on
attachment 425555
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=425555&action=review
> Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.cpp:435 > + m_closeCallback();
It would probably be worth null checking m_closeCallback to make this more robust in case some tries to call tryClose twice in the future.
> Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.h:107 > + typedef RefCounter<DataTaskCounterType> DataTaskCounter;
"using DataTaskCounter = RefCounter<DataTaskCounterType>" is the cool new way to do this. Same with DataTaskCounterToken
> Source/WebKit/NetworkProcess/NetworkProcess.cpp:2330 > RefPtr<StorageQuotaManager> storageQuotaManager = weakThis ? this->storageQuotaManager(sessionID, origin) : nullptr;
If you used weakThis-> instead of this-> then you wouldn't need to capture this. That would be better because it wouldn't allow you to accidentally use an unchecked this pointer (which is easy to do).
Alex Christensen
Comment 13
2021-04-09 10:56:11 PDT
Comment on
attachment 425555
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=425555&action=review
> Source/WebKit/WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.cpp:62 > + send(Messages::NetworkConnectionToWebProcess::AddIDBConnection());
Should there be a corresponding remove idb connection message in the destructor?
Darin Adler
Comment 14
2021-04-09 11:32:43 PDT
Comment on
attachment 425555
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=425555&action=review
>> Source/WebKit/NetworkProcess/NetworkProcess.cpp:2330 >> RefPtr<StorageQuotaManager> storageQuotaManager = weakThis ? this->storageQuotaManager(sessionID, origin) : nullptr; > > If you used weakThis-> instead of this-> then you wouldn't need to capture this. That would be better because it wouldn't allow you to accidentally use an unchecked this pointer (which is easy to do).
This is excellent advice. Also, when something is ThreadSafeRefCounted, we typically need to ref it before dereferencing it, not just dereference a weak pointer. There is likely a reason that’s not needed here, but *generally* the idiom would be to put the weak pointer into a RefPtr first.
Sihui Liu
Comment 15
2021-04-09 14:07:50 PDT
Created
attachment 425650
[details]
Patch for landing
Sihui Liu
Comment 16
2021-04-09 14:21:01 PDT
Created
attachment 425652
[details]
Patch for landing
Sihui Liu
Comment 17
2021-04-09 14:22:27 PDT
Created
attachment 425653
[details]
Patch for landing
Sihui Liu
Comment 18
2021-04-09 14:29:19 PDT
Comment on
attachment 425555
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=425555&action=review
>> Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.cpp:435 >> + m_closeCallback(); > > It would probably be worth null checking m_closeCallback to make this more robust in case some tries to call tryClose twice in the future.
Added.
>> Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.h:107 >> + typedef RefCounter<DataTaskCounterType> DataTaskCounter; > > "using DataTaskCounter = RefCounter<DataTaskCounterType>" is the cool new way to do this. Same with DataTaskCounterToken
Cool.
>>> Source/WebKit/NetworkProcess/NetworkProcess.cpp:2330 >>> RefPtr<StorageQuotaManager> storageQuotaManager = weakThis ? this->storageQuotaManager(sessionID, origin) : nullptr; >> >> If you used weakThis-> instead of this-> then you wouldn't need to capture this. That would be better because it wouldn't allow you to accidentally use an unchecked this pointer (which is easy to do). > > This is excellent advice. > > Also, when something is ThreadSafeRefCounted, we typically need to ref it before dereferencing it, not just dereference a weak pointer. There is likely a reason that’s not needed here, but *generally* the idiom would be to put the weak pointer into a RefPtr first.
ah, I think we do need to ref it here. Updated in the patch.
>> Source/WebKit/WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.cpp:62 >> + send(Messages::NetworkConnectionToWebProcess::AddIDBConnection()); > > Should there be a corresponding remove idb connection message in the destructor?
NetworkProcess::connectionToWebProcessClosed should already cover this case.
EWS
Comment 19
2021-04-09 15:05:06 PDT
Committed
r275779
(
236352@main
): <
https://commits.webkit.org/236352@main
> All reviewed patches have been landed. Closing bug and clearing flags on
attachment 425653
[details]
.
Sihui Liu
Comment 20
2021-04-09 16:52:37 PDT
Comment hidden (obsolete)
Reopening to attach new patch.
Sihui Liu
Comment 21
2021-04-09 16:52:38 PDT
Comment hidden (obsolete)
Created
attachment 425666
[details]
[fast-cq] Patch
EWS
Comment 22
2021-04-09 16:54:24 PDT
Comment hidden (obsolete)
Committed
r275784
(
236355@main
): <
https://commits.webkit.org/236355@main
> All reviewed patches have been landed. Closing bug and clearing flags on
attachment 425666
[details]
.
Sihui Liu
Comment 23
2021-04-10 01:30:01 PDT
Comment hidden (obsolete)
Reopening to attach new patch.
Sihui Liu
Comment 24
2021-04-10 01:30:02 PDT
Comment hidden (obsolete)
Created
attachment 425680
[details]
[fast-cq] Patch
EWS
Comment 25
2021-04-10 01:33:21 PDT
Comment hidden (obsolete)
ChangeLog entry in Source/WebKit/ChangeLog contains OOPS!.
Sihui Liu
Comment 26
2021-04-10 01:37:52 PDT
Comment hidden (obsolete)
Created
attachment 425681
[details]
[fast-cq] Patch
EWS
Comment 27
2021-04-10 01:39:20 PDT
Comment hidden (obsolete)
Committed
r275794
(
236365@main
): <
https://commits.webkit.org/236365@main
> All reviewed patches have been landed. Closing bug and clearing flags on
attachment 425681
[details]
.
Sihui Liu
Comment 28
2021-04-10 09:23:22 PDT
Comment hidden (obsolete)
Reopening to attach new patch.
Sihui Liu
Comment 29
2021-04-10 09:23:24 PDT
Comment hidden (obsolete)
Created
attachment 425685
[details]
Patch for landing
Sihui Liu
Comment 30
2021-04-10 09:48:14 PDT
Comment hidden (obsolete)
Created
attachment 425686
[details]
Patch for landing
EWS
Comment 31
2021-04-10 10:20:24 PDT
Comment hidden (obsolete)
Patch 425685 does not build
EWS
Comment 32
2021-04-10 10:57:01 PDT
Committed
r275799
(
236370@main
): <
https://commits.webkit.org/236370@main
> All reviewed patches have been landed. Closing bug and clearing flags on
attachment 425686
[details]
.
Sihui Liu
Comment 33
2021-04-10 18:51:15 PDT
Reopened as the patch is reverted in
r275799
Sihui Liu
Comment 34
2021-04-12 08:28:41 PDT
Created
attachment 425748
[details]
Patch
EWS
Comment 35
2021-04-12 16:43:57 PDT
Committed
r275846
(
236411@main
): <
https://commits.webkit.org/236411@main
> All reviewed patches have been landed. Closing bug and clearing flags on
attachment 425748
[details]
.
Fujii Hironori
Comment 36
2021-04-26 23:07:34 PDT
Filed:
Bug 225089
– HashTableConstIterator's consistency assertion fails while closing m_webIDBServers in NetworkProcess::didClose since
r275846
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug