SCM

Forum: help

Monitor Forum | Start New Thread Start New Thread
RE: Asynchronous Notification [ reply ]
By: Edward Tanjoco on 2006-08-17 17:08
[forum:1001640]
Well I'm glad that I wasn't just imagining the error! Thanks for getting this fixed, and when I have some time I will remove the work around and see what I come up with.

Thanks,
Ed

RE: Asynchronous Notification [ reply ]
By: Francisco Figueiredo jr. on 2006-08-09 14:45
[forum:1001628]

Hi!

This fix is now in CVS.

We hope to have RC3 released soon. If you need it right now, please get it from cvs and give it a try.

Thanks Edward, and sorry for any problems this may have caused.

RE: Asynchronous Notification [ reply ]
By: Josh Cooley on 2006-08-08 23:25
[forum:1001627]
Edward,

Francisco came up with a test case last night that consistently reproduced the problem. The next build should have a fix. I'm glad you were able to work around the bug in the current version.

Josh

RE: Asynchronous Notification [ reply ]
By: Edward Tanjoco on 2006-08-08 17:38
[forum:1001625]
Hey Fellas,

Thanks for looking at this. I was never able to get to root cause of this issue and decided to by pass the notification system and create my own thread that pings the database for changes. Not the most elegant method but it is tested and works well enough for my application.

Regards,
Ed

RE: Asynchronous Notification [ reply ]
By: Josh Cooley on 2006-08-07 12:46
[forum:1001620]
Edward,

I got the same results as Francisco. I noticed the test app didn't have a lock around the ExecuteNonQuery in NotifyTest1. I don't know if that is the cause of the exception you are seeing, but it can cause problems if two commands execute on the same connection at the same time.

Josh

RE: Asynchronous Notification [ reply ]
By: Francisco Figueiredo jr. on 2006-08-06 16:46
[forum:1001619]

Please, let me know if you can reproduce this problem again. I are facing this problem lately but it is very difficult to reproduce. I think this may have some relation to new notification handling code on RC2.

Thanks in advance.

RE: Asynchronous Notification [ reply ]
By: Francisco Figueiredo jr. on 2006-08-06 16:45
[forum:1001618]

Hi Edward.

Unfortunately, on both .net 1.1 and 2.0 I couldn't reproduce your error.

This is the output I get:

PING!
PING!
PING!
PING!
PING!
PING!
Sending Notify
PING!
Got notified from MyCallback1!
PING!
PING!
PING!
PING!
PING!
PING!
PING!
PING!
PING!
PING!
PING!
PING!


I'm on win2k, .net 2.0 version: Framework version 2.0.50727


RE: Asynchronous Notification [ reply ]
By: Edward Tanjoco on 2006-07-06 02:13
[forum:1001497]
In my previous post you will find a test app that I think will demonstrate the problem I am seeing. After the callback happens the exception that it keeps spitting out is:

Pinger: Exception caught:System.NotSupportedException: This stream does not
support seek operations.
at System.Net.Sockets.NetworkStream.Seek(Int64 offset, SeekOrigin origin)
at System.IO.BufferedStream.FlushRead()
at System.IO.BufferedStream.WriteByte(Byte value)
at Npgsql.NpgsqlQuery.WriteToStream(Stream outputStream, Encoding encoding)
at Npgsql.NpgsqlReadyState.Query(NpgsqlConnector context, NpgsqlCommand command)
at Npgsql.NpgsqlConnector.Query(NpgsqlCommand queryCommand)
at Npgsql.NpgsqlCommand.ExecuteCommand()
at Npgsql.NpgsqlCommand.ExecuteNonQuery()
at NotificationTestApp.NotifyError.Pinger() in c:\notificationtestapp\notifyerror.cs:line 75

Please let me know if this code produces similar results on your end.

Regards,
Edward

RE: Asynchronous Notification [ reply ]
By: Edward Tanjoco on 2006-07-06 02:07
[forum:1001496]
using System;
using System.Threading;
using System.Diagnostics;
using Npgsql;
using HP.Mfp.Services.Security;

namespace NotificationTestApp
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class NotifyError
{
private const string connection = "Server=127.0.0.1;Port=5432;User=foo;Password=bar;Database=mydb;Encoding=UNICODE;Pooling=False;";

private NpgsqlConnection pingerConn = null;
private NpgsqlConnection updaterConn = null;

private static object syncRoot = new object();

private Thread pingWorker;

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
NotifyError test = new NotifyError();

test.NotifyTest1();

return;
}

public NotifyError()
{
pingerConn = new NpgsqlConnection(connection);
updaterConn = new NpgsqlConnection(connection);

pingerConn.Open();
updaterConn.Open();

pingWorker = new Thread(new ThreadStart(Pinger));
pingWorker.Start();
}

public void NotifyTest1()
{
Thread.Sleep(3000);
RegisterNotification();
Thread.Sleep(3000);

NpgsqlCommand notifyCommand = new NpgsqlCommand("NOTIFY notifytest", updaterConn);

Console.WriteLine("Sending Notify");
notifyCommand.ExecuteNonQuery();
}

public void Pinger()
{
try
{
NpgsqlCommand ping = new NpgsqlCommand(";", pingerConn);
pingerConn.Notification += new NotificationEventHandler(MyCallback1);

while (true)
{
System.Threading.Thread.Sleep(1000);
lock (syncRoot)
{
try
{
Console.WriteLine("PING!");
ping.ExecuteNonQuery();
}
catch (Exception e)
{
Console.WriteLine("Pinger: Exception caught:"+e);
}
}
}
}
catch (ThreadAbortException)
{
Debug.WriteLine("Pinger: The end has come!");
}
finally
{
pingerConn.Close();
}
}

private void RegisterNotification()
{
NpgsqlCommand listenCmd = new NpgsqlCommand("LISTEN notifytest", pingerConn);

lock (syncRoot)
{
try
{
listenCmd.ExecuteNonQuery();
}
catch(Exception e)
{
Debug.WriteLine("Register: Unknown exception caught:"+e.Message);
}
}
}

internal void MyCallback1(Object sender, NpgsqlNotificationEventArgs args)
{
Console.WriteLine("Got notified from MyCallback1!");
}
}
}

RE: Asynchronous Notification [ reply ]
By: Edward Tanjoco on 2006-06-30 17:06
[forum:1001485]
Sorry to leave this hanging for so long but I just got a chance to work on this again and here is what I found. It looks like I am getting a System.NotSupported exception when I try to send a command over the connection after I have received a notification. Is there something that I am supposed to do to reset the connection after receiving a notification?

Thanks,
Ed

RE: Asynchronous Notification [ reply ]
By: Francisco Figueiredo jr. on 2006-06-08 13:44
[forum:1001414]

This is strange...

What problem are you getting?

Syncnotification is false by default. So notification thread isn't created.

If you are specifying true then you aren't supposed to manually poll the database.



Asynchronous Notification [ reply ]
By: Edward Tanjoco on 2006-06-07 17:42
[forum:1001408]
Hello,

It seems that the old way of getting notifications has been broken in RC1. Was this expected? Should I no longer be able to manually poll the database by sending ";"? Would I need to manually set "Syncnotification=false" in the connection string?

Thanks,
Edward

Powered By FusionForge