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

TMVCConnectionsRepository - fCurrentConnectionsByThread: TDictionary<TThreadID, string>; #594

Closed
biware-repo opened this issue Nov 21, 2022 · 1 comment
Assignees
Labels
accepted Issue has been accepted and inserted in a future milestone bug
Milestone

Comments

@biware-repo
Copy link

TMVCConnectionsRepository.RemoveConnection does not remove connection from fCurrentConnectionsByThread.

The new default connection is added by every operation within ActiveRecord class, but it is not removed from dictionary after finished operation in TMVCConnectionsRepository.RemoveConnection procedure.

The list in fCurrentConnectionsByThread stays unchanged. Moreover by every request there is still new ThreadID wich pointing to actual thread but the list is keeping all old thread IDs.

According to this #563 (comment) I have found possible reason of AV.

So I had to edit MVCFramework.ActiveRecord.pas to temporary solve this issue.

procedure TMVCConnectionsRepository.RemoveConnection(const aName: string;
const RaiseExceptionIfNotAvailable: Boolean = True);
var
  lName: string;
  lKeyName: string;
  lConnHolder: TConnHolder;
begin
  lName := aName.ToLower;
  lKeyName := GetKeyName(lName);

  fMREW.BeginWrite;
  try
    if not fConnectionsDict.TryGetValue(lKeyName, lConnHolder) then
    begin
      if RaiseExceptionIfNotAvailable then
      begin
        raise Exception.CreateFmt('Unknown connection %s', [aName])
      end
      else
      begin
        Exit;
      end;
    end; 

    fConnectionsDict.Remove(lKeyName);

   //ADDED to remove actual connection from thread dictionary - issue 563
   fCurrentConnectionsByThread.Remove(TThread.CurrentThread.ThreadID);


    try
      FreeAndNil(lConnHolder);
    except
      on E: Exception do
      begin
        LogE('ActiveRecord: ' + E.ClassName + ' > ' + E.Message);
        raise;
      end;
    end;
  finally
    fMREW.EndWrite;
  end;
end;
@danieleteti danieleteti self-assigned this Nov 21, 2022
@danieleteti danieleteti added bug accepted Issue has been accepted and inserted in a future milestone labels Nov 21, 2022
@danieleteti danieleteti added this to the 3.2.3-radium milestone Nov 21, 2022
@danieleteti
Copy link
Owner

Thanks! Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Issue has been accepted and inserted in a future milestone bug
Projects
None yet
Development

No branches or pull requests

2 participants