Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

google-cloud-logging: LoggingImpl.pendingWrites remove before add (with suggested fix) #4668

Closed
spkrka opened this issue Mar 12, 2019 · 2 comments
Assignees
Labels
api: logging Issues related to the Cloud Logging API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@spkrka
Copy link

spkrka commented Mar 12, 2019

In LoggingImpl, it is possible to leak memory in pendingWrites, if the future completes before the callback is added. If so, the callback runs before the call to pendingWrites.remove()

  @Test
  public void testMemoryLeak() {
    WriteLogEntriesRequest request =
            WriteLogEntriesRequest.newBuilder()
                    .addAllEntries(
                            Iterables.transform(
                                    ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2), LogEntry.toPbFunction(PROJECT)))
                    .build();
    WriteLogEntriesResponse response = WriteLogEntriesResponse.newBuilder().build();
    EasyMock.expect(loggingRpcMock.write(request)).andStubReturn(ApiFutures.immediateFuture(response));
    EasyMock.replay(rpcFactoryMock, loggingRpcMock);
    logging = options.getService();
    LoggingImpl impl = (LoggingImpl) logging;
    assertEquals(0, impl.pendingWrites.size());
    for (int i = 0; i < 1000; i++) {
      logging.write(ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2));
    }
    logging.flush();
    assertEquals(0, impl.pendingWrites.size());
  }

A proposed fix is to move this code to between creating the future and adding the callback.

        synchronized (writeLock) {
          pendingWrites.add(writeFuture);
        }
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Mar 13, 2019
@sduskis sduskis added api: logging Issues related to the Cloud Logging API. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. and removed triage me I really want to be triaged. labels Mar 14, 2019
@spkrka
Copy link
Author

spkrka commented Mar 19, 2019

PR: #4696

@ajaaym
Copy link
Contributor

ajaaym commented Mar 19, 2019

fixed with #4696

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the Cloud Logging API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

4 participants