PacketFence - BTS - PacketFence
View Issue Details
0001152PacketFenceupstreampublic2011-01-13 12:432011-01-18 09:54
obilodeau 
obilodeau 
normalminorrandom
resolvednot fixable 
 
 
0001152: FreeRADIUS hangs in our perl module with: Modification of a read-only value .../DBI.pm line 563
Error: rlm_perl: perl_embed:: module = /etc/raddb/rlm_perl_packetfence.pl , func = post_auth exit status= Modification of a read-only value attempted at /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/DBI.pm line 563.

Launching db connection in FreeRADIUS' CLONE {...} then re-connecting only if necessary should mitigate the issue. Here's a patch for those interested:

--- pf/addons/802.1X/rlm_perl_packetfence.pl	c967f44b9c3e832b4c2189e5792b47c1006872cd
+++ pf/addons/802.1X/rlm_perl_packetfence.pl	4c5b8f74db3f0770ba542f020d98a1e74ffa1371
@@ -37,6 +37,7 @@ use vars qw(%RAD_REQUEST %RAD_REPLY %RAD
 use vars qw(%RAD_REQUEST %RAD_REPLY %RAD_CHECK);
 #use Data::Dumper;
 
+our $mysql_connection;
 # This is hash wich hold original request from radius
 #my %RAD_REQUEST;
 # In this hash you add values that will be returned to NAS.
@@ -221,6 +222,22 @@ sub log_request_attributes {
         }
 }
 
+sub CLONE {
+    db_connect();
+}         
+
+sub db_connect {
+        
+    $mysql_connection = DBI->connect("dbi:mysql:dbname=".DB_NAME.";host=".DB_HOSTNAME,

+                                        DB_USER, DB_PASS, {PrintError => 0});
+        
+    if (!defined($mysql_connection)) {
+      openlog("rlm_perl_packetfence", "perror,pid","user");
+      syslog("info", "Can't connect to the database.");
+      closelog();
+    }     
+}         
+
 # Here is the decision process:
 # 
 # registered, guest, secure                      => disconnect (-1)
@@ -250,14 +267,16 @@ sub getVlan {
     
     openlog("rlm_perl_packetfence", "perror,pid","user");
     syslog("info", "getVlan called with switch_ip $switch_ip, mac $mac, is_eap_request 
$is_eap_request");
-    
-    # create database connection
-    my $mysql_connection = DBI->connect("dbi:mysql:dbname=".DB_NAME.";host=".DB_HOSTNAME, 

-                                        DB_USER, DB_PASS, {PrintError => 0});
+          
+    if (!defined($mysql_connection) || !$mysql_connection->ping() ) { 
+      syslog("info", "Database connection seems down.. Reconnecting...");
+      db_connect();
 
-    if (!defined($mysql_connection)) { 
-      syslog("info", "Can't connect to the database.");
-      return undef;
+      if (!defined($mysql_connection) || !$mysql_connection->ping() ) {
+        syslog("info", "Database still down... Bailing out for this request.");

+        closelog();
+        return;
+      }
     }
 
     # check if mac exists already in database
@@ -402,7 +421,6 @@ sub getVlan {
     # return the correct VLAN, close resources
     syslog("info", "returning VLAN $correctVlan for $mac");
     closelog();
-    $mysql_connection->disconnect();
     return $correctVlan;
 }
 
No tags attached.
Issue History
2011-01-13 12:43obilodeauNew Issue
2011-01-13 12:43obilodeauStatusnew => assigned
2011-01-13 12:43obilodeauAssigned To => obilodeau
2011-01-13 12:44obilodeauNote Added: 0001809
2011-01-13 12:44obilodeauStatusassigned => resolved
2011-01-13 12:44obilodeauResolutionopen => not fixable
2011-01-18 09:54obilodeauNote Added: 0001812

Notes
(0001809)
obilodeau   
2011-01-13 12:44   
Our code is no longer doing database access so this issue will not occur with anything > 2.0.

Issue was filed only for reference.
(0001812)
obilodeau   
2011-01-18 09:54   
by the way the CLONE { ... } above suggestion did not work.

Look into
https://github.com/alandekok/freeradius-server/blob/master/doc/bugs [^]
for more in-depth FreeRADIUS troubleshooting.