diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 09c44502cdf97a9c22e2c92e91b53136075806db..829126fee05e56ec1851c6cbc7007c061065c76c 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -4,6 +4,10 @@ class ApplicationController < ActionController::Base
 
   helper_method :abilities, :can?
 
+  rescue_from Gitosis::AccessDenied do |exception|
+    render :file => File.join(Rails.root, "public", "gitosis_error"), :layout => false
+  end
+
   protected 
 
   def abilities
diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb
new file mode 100644
index 0000000000000000000000000000000000000000..c37f10a39f383ceaba89b204d8ccf227889473fb
--- /dev/null
+++ b/app/controllers/errors_controller.rb
@@ -0,0 +1,5 @@
+class ErrorsController < ApplicationController
+  def gitosis
+    render :file => File.join(Rails.root, "public", "gitosis_error"), :layout => false
+  end
+end
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 3307ac23d9b32f9c14bb4a78b057abaad6eb0803..080a6ee62f630818d043f399435aaae8214c6c72 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -105,6 +105,8 @@ class ProjectsController < ApplicationController
         format.json { render json: @project.errors, status: :unprocessable_entity }
       end
     end
+  rescue Gitosis::AccessDenied
+    render :js => "location.href = '#{errors_gitosis_path}'" and return
   rescue StandardError => ex
     @project.errors.add(:base, "Cant save project. Please try again later")
     respond_to do |format|
diff --git a/config/application.rb b/config/application.rb
index 00ed1a71b735a8de86c539d237273f3eb8487d22..9a4fd4e4586ef2301d0b01501e2a2b8375dd1419 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -16,7 +16,7 @@ module Gitlab
     # -- all .rb files in that directory are automatically loaded.
 
     # Custom directories with classes and modules you want to be autoloadable.
-    # config.autoload_paths += %W(#{config.root}/extras)
+    config.autoload_paths += %W(#{config.root}/lib)
 
     # Only load the plugins named here, in the order given (default is alphabetical).
     # :all can be used as a placeholder for all plugins not explicitly named.
diff --git a/config/routes.rb b/config/routes.rb
index 332fd8b153fc25d60c876545021d84c7432416ac..00106b119a67f50403dc841b54098af7b0d95351 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -10,6 +10,7 @@ Gitlab::Application.routes.draw do
     root :to => "users#index"
   end
 
+  get "errors/gitosis" 
   get "profile/password", :to => "profile#password"
   put "profile/password", :to => "profile#password_update"
   get "profile", :to => "profile#show"
diff --git a/lib/gitosis.rb b/lib/gitosis.rb
index 383a96129df4ffb52dfac924d9c845728dd6ac68..e84eb891ab6cb28a60a98dd5911a63c26721dcae 100644
--- a/lib/gitosis.rb
+++ b/lib/gitosis.rb
@@ -1,6 +1,7 @@
 require 'inifile'
-
+require 'timeout'
 class Gitosis
+  class AccessDenied < StandardError; end
 
   def pull
     # create tmp dir
@@ -20,15 +21,19 @@ class Gitosis
   end
 
   def configure
-    File.open(File.join(Dir.tmpdir,"gitme-gitosis.lock"), "w+") do |f|
+    status = Timeout::timeout(5) {
+      File.open(File.join(Dir.tmpdir,"gitme-gitosis.lock"), "w+") do |f|
       f.flock(File::LOCK_EX)
-      
+
       pull
       yield(self)
       push
-      
+
       f.flock(File::LOCK_UN)
-    end
+      end
+    }
+  rescue Exception => ex
+    raise Gitosis::AccessDenied.new("gitosis timeout")
   end
 
   def destroy_project(project)
@@ -51,7 +56,7 @@ class Gitosis
     `cd #{File.join(@local_dir,'gitosis')} ; git rm keydir/#{user}.pub`
   end
 
-   #update or create
+  #update or create
   def update_project(repo_name, name_writers)
     # write config file
     conf = IniFile.new(File.join(@local_dir,'gitosis','gitosis.conf'))
@@ -61,5 +66,4 @@ class Gitosis
 
     conf.write
   end
-
 end
diff --git a/public/gitosis_error.html b/public/gitosis_error.html
new file mode 100644
index 0000000000000000000000000000000000000000..be751d6e5e6924c9c7ef0505c31240dc50b97c70
--- /dev/null
+++ b/public/gitosis_error.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>We're sorry, but we cant get access to your gitosis</title>
+  <style type="text/css">
+    body { background-color: #EAEAEA; color: #666; text-align: center; font-family: arial, sans-serif; }
+    div.dialog {
+      width: 600px;
+      padding: 0 4em;
+      margin: 4em auto 0 auto;
+    }
+    h1 { font-size: 48px; color: #444; line-height: 1.5em; }
+    h2 { font-size: 24px; color: #666; line-height: 1.5em; }
+  </style>
+</head>
+
+<body>
+  <!-- This file lives in public/500.html -->
+  <div class="dialog">
+    <h1>Gitosis Error</h1>
+    <h2>We're sorry, but we cant get access to your gitosis.</h2>
+    <h3> 1. Check 'config/gitosis.yml' for correct settings.</h3>
+    <h3> 2. Be sure web server user has access to gitosis.</h3>
+  </div>
+</body>
+</html>